返回时uitableview的问题

时间:2011-06-14 22:38:55

标签: iphone objective-c

我有一个带有表视图的viewcontroller,当我点击一个单元格时,我会导航到另一个具有另一个tableview的视图控制器。

我尝试在第一个viewcontroller中使用viewDidAppear和viewWillAppear,当我从第二个viewcontroller返回到这个viewcontroller时,我将输入这个方法之一。

问题是当我返回此viewcontroller时他没有输入此方法。

这是我进入第二个视图控制器的方式:

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        ProfileViewController2 *tmp = [[ProfileViewController2 alloc]initWithType:indexPath.row string:[self.array2 objectAtIndex:indexPath.row]];
        [[self navigationController] pushViewController:tmp animated:YES];
        [tmp release];
        [self.mytableview deselectRowAtIndexPath:indexPath animated:YES];
    }

1 个答案:

答案 0 :(得分:0)

viewWillAppearviewDidAppear在iOS上声名狼借。

如果您正在使用UITableView,我们总是在表格加载到

之前放置我们需要运行的代码
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

功能。这是一个轻微的黑客,但工作得很好,因为这是UITableViewDataSource协议中的第一个函数。

或者,您可以致电

    [tmp viewDidAppear];

在推动视图控制器之后,在释放tmp之前强制调用该函数。