拜框架所赐,要生成
一个乖仔列表的妈妈窗口,和一个乖崽详细信息的子窗口,
并且关联好妈妈生儿子,儿子投入妈妈怀抱里
这样的互动相当简单,只需下面的四步。
复杂的原理不讲了,主要是为了简单的记录简单的代码
//1,妈妈窗口加按钮
- (void)setupNavButtons
{
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd
target:self
action:@selector(addButtonPushed:)] autorelease];
[self.navigationItem setRightBarButtonItem:addButton];
}
//2,妈妈窗口加按钮的生新崽崽的事件
- (void)addButtonPushed:(id)sender
{
sonViewController *addSonViewController = [[[sonViewController alloc] initWithStyle:UITableViewStyleGrouped] autorelease];
[self.navigationController pushViewController:addStudentViewController animated:YES];
}
//,3,崽崽窗口加返回妈妈窗口的按钮
- (void)setupNavButtons
{
//右上角添加按钮和按钮的触法事件。doneButtonPushed:
UIBarButtonItem *doneButton = [[[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemDone
target:self
action:@selector(doneButtonPushed:)] autorelease];
[self.navigationItem setRightBarButtonItem:doneButton];
}
//,4,崽崽窗口返回妈妈窗口时候触发的事件
- (void)doneButtonPushed:(id)sender
{
//TODO 返回数据
[self.navigationController popViewControllerAnimated:YES];
}
母子各有一个按钮,关键是pushViewController和 popViewControllerAnimated搭配好啊
真只有四步么,其实在AppDelegate里面得先有这两块代码才可以呢:
1,添加两个实例变量:
UINavigationController *navController;
SonListViewController *sonListViewController;
2,在applicationFinishLaunching那个方法里面初始化它们和它们的关系
navController = [[UINavigationController alloc] init];
sonListViewController = [[SonListViewController alloc] init];
把妈妈窗口嵌在navController里。
[navController pushViewController:sonListViewController animated:NO];