拜框架所賜,要生成 app
一個乖仔列表的媽媽窗口,和一個乖崽詳細信息的子窗口, 框架
而且關聯好媽媽生兒子,兒子投入媽媽懷抱裏 spa
這樣的互動至關簡單,只需下面的四步。 事件
複雜的原理不講了,主要是爲了簡單的記錄簡單的代碼 get
//1,媽媽窗口加按鈕 it
- (void)setupNavButtons io
{ 變量
UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] 原理
initWithBarButtonSystemItem:UIBarButtonSystemItemAdd List
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];