iOS代理不能使用performSegueWithIdentifier? [英] iOS delegate not working with performSegueWithIdentifier?

查看:154
本文介绍了iOS代理不能使用performSegueWithIdentifier?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在故事板中有两个控制器(第一,第二),xcode 4.2。

I have two controllers (first,second) in a storyboard, xcode 4.2.

第一个控制器有一个表视图并嵌入在导航控制器中。
第二个控制器也有一个表视图,并嵌入导航控制器(与第一个控件不一样)

First controller has a tableview and embedded in navigation controller. Second controller has a tableview too and embedded in navigation controller (not same as the first)

在first.h中:

#import "second.h"
...
@interface first : UIViewController <secondDelegate, UITableViewDelegate, UITableViewDataSource>
...

在first.m:

- (IBAction)add:(id)sender // action when tapped a button on topbar
{
    [self performSegueWithIdentifier:@"addSegue" sender:sender];
}

....

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if([[segue identifier] isEqualToString:@"addSegue"])
    {
        NSLog(@"delegated");
        second *controller=[segue destinationViewController];
        controller.delegate=self;
    }
}

- (void)callback
{
     NSLog(@"Callback here");
}

Segue是默认转换的模态段。

Segue is a modal segue with default transition.

second.h:

@protocol secondDelegate
   -(void)callback;
@end

....

id <secondDelegate> delegate;
@property (nonatomic,assign) id <secondDelegate> delegate;

second.m:

... (button of topbar tapped action) ...
[self dismissModalViewControllerAnimated:YES];
NSLog(@"class: %@",[self delegate]);
[[self delegate]entryGroupDoneButtonTapped];

总结:

我不看到回调这里的消息,但我有一个委托的消息。 class:调试行打印null。

I don't see the "callback here" message, but I've got a "delegated" message. The "class: " debug line print "null".

为什么?

(我可以发送任何数据

推荐答案

我找到了一个解决方案: destinationViewController 返回一个 UInavigationController ,所以我们可以使用: AddDrinkViewController * controller = [[[segue destinationViewController] viewController] objectAtIndex: 0];

I found a solution: the destinationViewController returns a UInavigationController, so we can use: AddDrinkViewController *controller=[[[segue destinationViewController]viewControllers]objectAtIndex:0];

这篇关于iOS代理不能使用performSegueWithIdentifier?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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