0

在从堆栈上的视图调用下面的代码之前或之后,我想在程序将弹出的根视图上设置标签的文本。

[self.navigationController popViewControllerAnimated:YES];

将视图控制器推入堆栈时,我可以用另一种方式(如下所示),但我不知道从堆栈弹出时该怎么做

- (PushedViewController *) pushedViewController {
NSLog(@"Initialise view");
if (pushedViewController == nil) {
    pushedViewController = [[PushedViewController alloc] initWithNibName:@"PushedView" bundle:nil];
}
return pushedViewController;
}

#pragma mark -
#pragma mark Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

[TableView deselectRowAtIndexPath:indexPath animated:YES];


Table* tableRow =[fetchedResultsController objectAtIndexPath:indexPath];

[self.navigationController pushViewController:self.pushedViewController animated:YES];
self.pushedViewController.code.text = tablerow.code;

}

如果有人能告诉我如何在不创建视图的新实例的情况下访问和设置堆栈上的视图变量,将不胜感激。

4

1 回答 1

1

您真正想要的是进行类似委托的回调。这样你的孩子控制器就会有

@protocol PushedViewControllerDelegate
@required

- (void)controller:(PushedViewController *)controller didUpdateSome:(id)data;

@end

和一个财产

@property (nonatomic, assign) id<PushedViewControllerDelegate> delegate

现在,您可以将根控制器分配给delegate子控制器,它可以通知任何所需的更改。

于 2012-08-12T09:20:14.527 回答