【发布时间】:2011-12-07 14:03:52
【问题描述】:
我的协议有问题。
我的“初始视图控制器”是一个导航控制器。在根页面上,我显示了另一个导航控制器,其中嵌入了视图控制器。 onclick 一个 segue 应该被触发......这很有效,但是从“ViewController”的委托方法永远不会被调用。
我添加的图像是我如何在 iOS 5 中使用 InterfaceBuilder 在 2 个 NavigationController 之间建立连接的示例。
MyViewController.h
@protocol MyProtocol <NSObject>
@required
- (void) myFunction:(NSString *)string;
@end
@interface MyViewController : UIViewController <MyProtocol>
@property (nonatomic, assign) id<MyProtocol> delegate;
@end
MyViewController.m
#import "MyViewController.h"
@implementation PropertyController
@synthesize delegate = _delegate;
- (void) myFunction:(NSString *)string {
[_delegate myFunction:string];
}
- (IBAction) callDelegate:(id)sender {
![enter image description here][1][self myFunction:@"test"];
}
这是从上方显示 NavigationController 的 ViewController 的代码
ViewController.h
#import "MyViewController.h"
@interface ViewController : UIViewController <MyProtocol>
ViewController.m
#import "ViewController.h"
@implementation ViewController
- (void) myFunction:(NSString *)string {
NSLog(@"myFunction was called");
}
- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
[((MyViewController *) segue.destinationViewController) setDelegate:self];
}
- (IBAction) showModalNavigationController {
[self performSegueWithIdentifier:@"NameFromSegueInInterfaceBuilder" sender:self];
}
我找不到解决问题的方法。
希望有人能帮帮我
谢谢你:)
【问题讨论】:
标签: delegates uinavigationcontroller interface-builder ios5 segue