私はforDelegate.hファイルで 'Mydelegate'プロトコルを宣言するために私自身のデリゲートメソッドを作成しようとしています。デリゲートメソッドの作成方法
@protocol Mydelegate <NSObject>
-(void)show:(NSString *)msg;
@end
はその後、私はthis.Iのプロパティは、ボタンを押して上の呼び出しであるメソッドのclickMeを宣言作る私の最初のViewControllerに、そのボタンは私のfirstviewcontrollerの.xibファイル内に存在しています。次いで
@class SecondViewController;
@interface ViewController : UIViewController
{
id <Mydelegate> delegate1;
SecondViewController *secondController;
}
@property (assign) id <Mydelegate> delegate1;
-(IBAction)clickMe:(id)sender;
@end
と私は私の第2のビューコントローラでは、このプロトコルを採用し、このプロトコルの方法
SecondViewController.hファイル
@class ViewController;
@interface SecondViewController : UIViewController <Mydelegate>
{
ViewController *viewController;
}
SecondViewController.mファイル
-(void)show:(NSString *)msg
{
NSLog(@"in delegate mathod");
}
-(void)viewDidLoad
{
viewController =[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
viewController.delegate1=self;
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
}
を定義した後
プログラムは実行中ですが、Mydelegateのメソッド 'show'は呼び出されません。
あなたがあなたのshowメソッドを呼び出す場所あなたがどこで何かを使うべきです。 – vishiphone
私はあなたのコードを編集し、ちょうどそれをチェックアウトの下に投稿します。 – vishiphone
定義は " - (void)show:(NSString *)msg" SecondViewController内にありますか?また、SecondViewControllerでdelegate1を使用しました。 –