开发者

iPhone: remove section in TableView

I'm working with table view and sections...In some case I need do remove one section, in another set it back. I can do that in 2 ways: 1)

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    if (somecase) {
        return 2;
    } else {
        return 3;
    }
}

and than

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    UITableViewCell *tableViewCell = [[UITableViewCell alloc] initWi开发者_运维百科thStyle:UITableViewCellStyleValue1 reuseIdentifier:nil];
    [tableViewCell autorelease];

    tableViewCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (sectionNumber == 3 {
        switch (indexPath.section) {
            case 0:
                break;
            case 1:
                break;
            case 2:
                break;
        }
    } else if (sectionNumber == 2) {
        switch (indexPath.section) {
            case 0:
                break;
            case 1:
                break;
        }
        return tableViewCell;
    }
}

And a second way is to implement

[self.tableView beginUpdates];
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:NO];
[self.tableView endUpdates];

But it's not working...I put this methods to ViewDidLoad, is that ok ? Or I should put in somewhere else ? Or what is the problem ?

And what is the best practice for removing section ? first one or second ? thanks....


  • set condition that will satisfy "somecase " then reload tableview

[tableview reloadData];

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜