【问题标题】:iOS delegate not working with performSegueWithIdentifier?iOS 委托不能与 performSegueWithIdentifier 一起使用?
【发布时间】:2011-12-13 15:07:33
【问题描述】:

我在情节提要 xcode 4.2 中有两个控制器(第一个,第二个)。

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

在 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。

秒.h:

@protocol secondDelegate
   -(void)callback;
@end

....

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

秒.m:

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

总结:

我没有看到“此处回调”消息,但我收到了“委托”消息。 “class:”调试行打印“null”。

为什么?

(我可以用这个从第一个到第二个发送任何数据,只有委托的回调不起作用)

【问题讨论】:

  • 已解决:我找到了解决方案:destinationViewController 返回一个 UI 导航控制器,因此我们可以使用:AddDrinkViewController *controller=[[[segue destinationViewController]viewControllers]objectAtIndex:0];
  • 您能用您的解决方案回答您的问题吗? :-)

标签: ios xcode delegates segue


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 2017-04-16
    • 2011-03-23
    • 1970-01-01
    • 1970-01-01
    • 2014-12-09
    • 2012-05-19
    相关资源
    最近更新 更多