プロトコルに問題があります。モーダル提示NavigationController(iOS 5 - ストーリーボード)を使用している場合、デリゲートが機能しません
私の「初期View Controller」はナビゲーションコントローラです。ルートページには、View Controllerが組み込まれている他のナビゲーションコントローラが表示されます。 segueをonclickする必要があります。これは完全に動作しますが、 "ViewController"のデリゲートメソッドは呼び出されません。
Iを加えた画像は、私はIOSの5
MyViewController.hにInterfaceBuilderで2 NavigationControllers間の接続を構築する方法の例である
@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"];
}
ViewController.h
上記
#import "MyViewController.h"
@interface ViewController : UIViewController <MyProtocol>
からNavigationControllerを示しているのViewControllerのコード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];
}
は、私は私の問題の解決策を見つけるカントです。私は誰かが私に
を助けることを願って
はあなたに感謝:)私はここでの問題のカップル見
こんにちは、ありがとう、私はその第2のナビゲーションコントローラが必要です。だから私はprepareForSegueの実装を変更する必要があります。どのように私はMyViewControllerからデリゲートを設定することができますか? – Haegar
これはストーリーボードを扱う際の一般的な必要性なので、私はこのために 'UIStoryboardSegue'のカテゴリを実装します。私の[回答](http://stackoverflow.com/questions/8041237/how-to-set-the-delegate-with-a-storyboard/8041666#8041666)を別のストーリーボードの質問にしてください。 –
ありがとうございました!今私はtopViewControllerからデリゲートをselfに設定し、今は動作します! :) [((MyViewController *)((UINavigationController *)segue.destinationViewController).topViewController))setDelegate:self]; – Haegar