【发布时间】:2013-05-15 14:25:21
【问题描述】:
所以我得到了一个带有 4 个单独按钮的 ViewController。单击 button1 时,TableViewController1 会弹出带有项目列表的 ViewController。选择项目时,TableViewController1 会下拉,并且 button1 现在具有在表格中选择的文本。这一切都很好。但是,当我使用 TableViewController2 对 button2 执行完全相同的操作时,来自 button1 的数据将被重置。
我使用带有标识符的segues,一些代码:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
if ([segue.identifier isEqualToString:@"showEducation"]) {
NSIndexPath *indexPath = [self.tableViewEducation indexPathForSelectedRow];
ViewController *destViewController = segue.destinationViewController;
destViewController.educationText = [tableViewArray objectAtIndex:indexPath.row];
}
}
所以目前我为每个按钮获得了多个 segue 标识符,为 tableviews 获得了多个 .h 和 .m 文件。我是否使用了完全错误的技术来使其正常工作?我希望我足够清楚,否则我可以上传图片。
编辑:我刚刚注意到,我的 ViewController 上还有一个滑块。单击按钮并在 TableView 中选择一行时,滑块将重置为原始位置。和上面一样的问题。
【问题讨论】:
-
您的两个独立的 TableViewController 对象是否使用相同的对象/类作为其数据源?
-
你到底是什么意思?
-
一个类或对象有你的“
cellForRowAtIndexPath”方法,还是每个 TableViewController 对象都有自己的? -
每个 TableViewController 都有自己的。这是错的吗?
-
如果不了解您在控制器之间来回切换的方式,很难判断您在做什么。你什么时候看到按钮 1 的数据被重置了——你是回到第一个控制器看到的,还是总是能看到这 4 个按钮?