分段UITableView刷新



在我的应用程序是UITableView在弹出窗口,它重新加载时新的数据。如果表没有分段,则使用以下代码可以完美地工作:

启动重新加载的通知:

- (void)recieveNotification:(NSNotification*) notification {
if ([[notification name] isEqualToString:@"NewDataArrived"]) {
    [self viewWillAppear:YES];
}

方法重新加载:

- (void)viewWillAppear:(BOOL)animated
{
//Formation of the new content of table
[self.tableView reloadData];
[super viewWillAppear:animated];
}

但是如果我把内容按章节排序,一切都会变得混乱。视图没有重新加载,新数据只是添加到表的末尾,到最后一节。

节头:

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
if (section == 0) {
    return @"Cities";
} else
    if (section == 1) {
        return @"Hotels";
    } else 
        if (section == 2) {
            return @"Airports";
        } else
return @"Landmarks";
}

这是截图http://dl.dropbox.com/u/8288064/img/chaos.png。

我花了很多时间来解决这个问题,如有任何建议,我将不胜感激。

就像这样做!!!!

. h

   -(void)myOwnMethod:(id)sender;

m

-(void)myOwnMethod:(id)sender{
    [self.tableView reloadData];

}
- (void)recieveNotification:(NSNotification*) notification {
    if ([[notification name] isEqualToString:@"NewDataArrived"]) {
            //  [self viewWillAppear:YES];
        [self myOwnMethod];
    }
}   

最新更新