开发者

how to delete a row in a section and hiding the section?

I am having an issue where when i have two sections let say section x and section. Section x has one row and also section y. If i delete a row in section y which is the second one, it will delete the row in section x and keeping the row in section y also it leave a space when i hide the section if their is a way to hide the section which wont make a mess please tell me a way here are some picture that might let u understand my question

how to delete a row in a section and hiding the section?

how to delete a row in a section and hiding the section?

how to delete a row in a section and hiding the section?

and here is the code i use to delete a row

-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    int path;
    path = indexPath.row;
    [data removeObjectAtIndex:path];
    if([data count] == 0)
    {
        UIBarButtonItem *leftbutton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemEdit target:self action:@selector(editTable)];
      开发者_运维知识库  self.navigationItem.rightBarButtonItem = leftbutton;
        [leftbutton release];
        [self.navigationItem.rightBarButtonItem setEnabled:FALSE];
        [mainTableView setHidden:TRUE];
    }
    else
    {
        [self.navigationItem.rightBarButtonItem setEnabled:TRUE];
        [mainTableView setHidden:FALSE];
    }

    [self saveData];
    [mainTableView reloadData];
}


To remove a section when you have deleted all rows belonging to it, call - (void)deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation & return one less from - (NSInteger)numberOfSections.

You haven't added any code that shows how you are deleting a row from the table (removing it from data isn't sufficient). Try something like-

    [self.tableView beginUpdates];
    [data removeObjectAtIndex:path];
    [self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
    [self.tableView endUpdates];


Well at the beginning i wasn't able to solve the issue but with the help of @Akshay my first problem was while deleting it always delete the section on top the section i was deleting to solve the issue i just had to update the number of rows in a section using [mainTableView reloadData]; before the return expression

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜