如何在Xcode 4.2故事板上正确使用模式视图控制器 [英] How to properly use modal view controller with the xcode 4.2 storyboard

查看:81
本文介绍了如何在Xcode 4.2故事板上正确使用模式视图控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道如何正确使用情节提要来模态地设置视图控制器.我个人更喜欢使用xibs,但是故事板似乎越来越受欢迎,并且将成为未来的发展之路.

I was wondering how to properly use the storyboard to put up a view controller modally. Personally I prefer working with xibs, but it seems that the storyboard is gaining popularity and will be the way to go in the future.

我通常以模态形式放置视图控制器的方式如下:假设我们有ViewControllerA(简称A)和ViewControllerB(简称B). 然后,通常我会在B.h中放置一个协议,以在B要被取消时指定委托方法,并添加id<theProtocol> delegate字段作为assign属性.假设我在A忙,想以模态呈现B,我会写:

The way I would normally put up a view controller modally would be like this: let's say we have ViewControllerA (A for short) and ViewControllerB (B for short). I would then normally put a protocol in B.h specifying the delegate method when B wants to be dismissed and add the id<theProtocol> delegate field as an assign property. Assuming i'm busy in A and I want to present B modally, I would write:

B* b = [[B alloc] initWithNibName:@"B" bundle:nil];
b.delegate = self;
[self presentModalViewController:B animated:YES];

使用情节提要,我知道可以通过从按钮到视图控制器的ctrl拖动并选择模式作为过渡类型,以模式方式放置其他视图控制器.我只是想知道;在哪里设置新视图控制器的委托?将事物传递到模态视图控制器的正确做法是什么?我真的不知道与塞格斯的全部交易是什么...

Using the storyboard, I know it's possible to put up a different view controller in a modal way by ctrl-dragging from a button to a viewcontroller and selecting modal as transition type. I'm just wondering though; where do I set the delegate of the new view controller? What's the correct practice of passing things to your modal view controller? I don't really know what the whole deal with Segues is...

推荐答案

看看教程

根据它,您应该将委托设置如下:

According to it, you should set the delegate as follows:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"AddPlayer"])
    {
        UINavigationController *navigationController = 
          segue.destinationViewController;
        PlayerDetailsViewController 
          *playerDetailsViewController = 
            [[navigationController viewControllers] 
              objectAtIndex:0];
        playerDetailsViewController.delegate = self;
    }
}

@"AddPlayer"是您的模态"脚本的名称

Where @"AddPlayer" is the name of your 'modal' segue

这篇关于如何在Xcode 4.2故事板上正确使用模式视图控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆