将2个或更多UIViewController类添加到导航堆栈

时间:2014-07-23 12:23:43

标签: ios iphone objective-c uiviewcontroller uinavigationcontroller

我有一个可重复使用的UIViewController类,其中有一个tableview,比如Class T.我有一个要显示的内容列表。

现在当我按下其中一个单元格时,我创建了这个类的一个新实例(alloc init)并将其推送到导航堆栈并在同一个类T中显示新数据。

当我弹出控制器时它会转到第一个实例,如果同一个类,但tableview显示第二个实例中显示的数据,则会出现问题。

我正在为T类使用XIB而不是故事板和segues。

请帮我解决这个问题。

谢谢,

[编辑 - 我]初始化

T *controller = [T alloc] initWithNibName:@"T" bundle:nil];
[self.navigationController pushViewController:controller animation:YES];

1 个答案:

答案 0 :(得分:0)

您的问题显然是基于表格视图datasource中使用的数据缺失更新。我建议每个控制器获得自己的对象,数组或获取结果控制器。然后你可以这样做:

T *controller = [T alloc] initWithNibName:@"T" bundle:nil];
controller.dataArray = ... // populate the data source

或者,使用相同的datasource,您必须确保检查应显示的内容。也许你可以给你的表视图控制器类一个type属性,在显示数据单元格时会检查它。

if (self.type == HierarchyFirstLevel) {
   cell.textLabel.text = ... // populate for first level
}
else if (self.type == HierarchySecondLevel) {
   cell.textLabel.text = ... // something else
}
// etc.