Xcode 4.3 StoryBoard 基础 事件和跳转处理

来源:互联网 发布:淘宝侵犯肖像权赔偿 编辑:程序博客网 时间:2024/05/29 09:22

刚学iOS 就直接用 xcode 4.3  头瞬间大了  不过学了 之后发现比之前的xib 方便好多也满顺手  只是网络上的教程不多 。

下面是页面进行跳转的方法


页面上跳转 一般有两种   一种是 用view 当事件源。 比如上图 按住control 点击button 直接拉到 下个界面

 当点击 button  就直接跳转 连接的界面。

还有种 是controller 连接 controller 。  就是 两个界面直接拉   然后设置 中间线 segue 的identifier 按自己喜好输

然后 在你要跳转的代码段中 加

[selfperformSegueWithIdentifier:@"gotoOther"sender:self];


下面新建个UIViewController

这是 .h 文件

#import<UIKit/UIKit.h>


@interface firstController :UIViewController


@end

回到storyboard  点击第一个界面  设置它的 class 为刚建的firstController



接着点击 然后界面变成

你可以看到与当前界面绑定的controller 代码

直接按住control 从 button 拉到代码中  系统会自动弹出选择筐  你可以选它为 outlet 或者是 事件



那你就可以写代码拉    还可以把多个事件 绑定到同一个方法中 

- (IBAction)bt_pressed:(id)sender {

    

    if([bt_go isEqual:sender])

    {

        [selfperformSegueWithIdentifier:@"gotoOther"sender:self];

    }

    if([bt_cancel isEqual:sender])

    {

        exit(0);

    }

}

可以直接选择事件进行绑定



有时候 你会发现代码不对    可以通过automatic 选择正确的文件

最后是一些跳转和返回的方法

 //根据 segue Identifier跳转界面

    [self performSegueWithIdentifier:@"GotoTwo" sender:self];

    

   //modal 方式跳转

    [self presentModalViewController:nil animated:YES];

    

   //压进一个viewcontroller

    [self.navigationController pushViewController:nil animated:YES];


   //弹出一个viewcontroller  相当与返回上一个界面

    [self.navigationController popViewControllerAnimated:YES];

    

   //  modal跳转的返回方法

    [self dismissModalViewControllerAnimated:YES];


转帖:http://blog.csdn.net/li6185377/article/details/7456458

原创粉丝点击