2012-08-12 28 views
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; 

} 

時如果有人能告訴我如何在堆棧中訪問和設置視圖的變量而不創建視圖的新實例,那將是值得讚賞的。

+0

'[[[navigationController rootViewController] textLabel] setText:@「Foo」];' – 2012-08-12 08:17:55

+0

@ H2CO3當我這樣做,我得到錯誤「沒有已知的選擇器rootViewController的類方法」也將允許我設置文本一個文本框? – msec 2012-08-12 08:28:49

+0

對不起,我的意思是說方法名稱爲topViewController。 – 2012-08-12 08:36:01

回答

1

你真正想要的是做一個委託式的回調。所以,你的孩子控制器將有

@protocol PushedViewControllerDelegate 
@required 

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

@end 

和財產

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

現在,您可以將根控制器分配到子控制器的delegate,它可以通知回要求的任何變更。

相關問題