iOS 委托无法与 PerformSegueWithIdentifier 一起使用?
我在故事板中有两个控制器(第一个,第二个),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。
secondary.h:
@protocol secondDelegate
-(void)callback;
@end
....
id <secondDelegate> delegate;
@property (nonatomic,assign) id <secondDelegate> delegate;
secondary.m:
... (button of topbar tapped action) ...
[self dismissModalViewControllerAnimated:YES];
NSLog(@"class: %@",[self delegate]);
[[self delegate]entryGroupDoneButtonTapped];
摘要:
我没有看到“此处回调”消息,但我收到了“委派”消息。 “class:”调试行打印“null”。
为什么?
(我可以用这个从第一个到第二个发送任何数据,只有委托的回调不起作用)
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)
In first.h:
#import "second.h"
...
@interface first : UIViewController <secondDelegate, UITableViewDelegate, UITableViewDataSource>
...
In 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 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];
Summary:
I don't see the "callback here" message, but I've got a "delegated" message. The "class: " debug line print "null".
Why?
(I can send any data from first to second with this, only delegate's callback not works)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了一个解决方案:
destinationViewController
返回一个UInavigationController
,因此我们可以使用:AddDrinkViewController *controller=[[[segue destinationViewController]viewControllers]objectAtIndex:0];
I found a solution: the
destinationViewController
returns aUInavigationController
, so we can use:AddDrinkViewController *controller=[[[segue destinationViewController]viewControllers]objectAtIndex:0];