iPhone母版详细信息应用程序如何使用详细信息视图更改母版视图中相应单元格中显示的文本值



我是iOS编程的新手,目前正在学校上iOS课。对于我正在做的一个项目,我们必须为 iPhone 编写一个基本的主从应用程序。对于我的应用程序,我正在创建一个简单的待办事项列表类型的应用程序。每个任务的名称显示在主视图中,任务的名称可以在详细信息视图中更改。我设置了一个保存按钮,按下时有一个展开 segue 委托。当我按下按钮时,我回到主视图,我无法实时更改相应单元格的值。我知道主视图正在取回更改的信息,因为在控件传输回主视图并保存之前,更改的信息不会被保存。当我重新运行应用程序时,将显示新名称而不是默认名称。

这是放松 segue 的代表

- (IBAction) done:(UIStoryboardSegue *)segue
{
// index for the cell in the master view table that was changed
NSIndexPath *changeIndex = [self.tableView indexPathForSelectedRow];
[self tableView:self.tableView cellForRowAtIndexPath:changeIndex];
// place the new dictionary entry created by the detail view in the location of the
// array where the old entry was located
_taskList[changeIndex.row] = self.ChangedEntry;
// store the change in the plist file
[_taskList writeToFile:self->documentPlistPath atomically:YES];
}

调用此函数,它似乎更改了表格中单元格的文本,但我不确定

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:  (NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
cell.textLabel.text = _taskList[indexPath.row][TASK_DATA_NAME];
return cell;
}

所以是的,我只是想弄清楚如何使主视图反映在详细信息视图中所做的更改,而无需关闭应用程序并重新打开它。哦,我正在使用Xcode 5并针对iOS 7。

基本上,在更新数据模型 ( _taskList ) 后,您需要通过调用表视图来刷新表视图reloadData。这会告诉它更新所有行。

最新更新