【发布时间】:2013-10-28 13:31:30
【问题描述】:
我有一个UINavigationController 层次结构,VC1 --> VC2。
VC1 有一个表格视图,当 VC2 完成工作时我需要重新加载它,所以 VC1 有这个代码:
-(void)viewWillAppear:(BOOL)animated
{
[[self tableView] reloadData];
}
VC2 本质上是与服务器一起在 VC1 中创建一个新的表行。当按下 VC2 中的完成按钮时,我调用[navController popViewControllerAnimated:YES]。所以从用户的角度来看会发生什么:
访问 VC2,用它为 VC1 中的表创建一个新行。按完成。
层次结构成功导航回 VC1,但
tableview不会重新加载并显示新行。但是,如果我随后导航到 VC2,并立即点击
navController后退按钮,则表确实重新加载并显示新行。
那么为什么[tableview reload] 对 3 起作用而不对 2 起作用?非常感谢。
==
更多代码回复answer mentioned below:
在应用委托中:
CWLandingVC *lvc = [[CWLandingVC alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:lvc];
[[self window] setRootViewController:navController];
在 VC0 中:
-(void)toSessionMgmtViewController
{
TSessionMgmtViewController *tsmvc = [[TSessionMgmtViewController alloc] init];
[[self navigationController] pushViewController:tsmvc animated:YES];
}
在 VC1 中:
- (IBAction)toCreateSessionView:(id)sender
{
TCreateSession *cs = [[TCreateSession alloc] init];
[[self navigationController] pushViewController:cs animated:YES];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[[self tableView] reloadData];
}
在 VC2 中: 完成与服务器的合作...
UINavigationController *navControler = [self navigationController];
[navControler popViewControllerAnimated:YES];
此外,当 VC2 完成与服务器的合作时,它会更新 TSession 的数据存储,称为 SessionListStore:
- (TSession *)addSession:(NSString *)code withName:(NSString *) name qs:(int)qs
{
TSession *s = [[TSession alloc] initWithName:name code:code numberQuestions:qs];
[_sessions setObject:s forKey:code];
return s;
}
其中 session 是 SessionListStore 中的 NSNutatbleDictionary。
非常感谢。
【问题讨论】:
标签: objective-c uitableview uinavigationcontroller