ios开发知识装逼2:简单的母子窗体交互

           

拜框架所赐,要生成 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];

相关文章
相关标签/搜索