ストーリーボード、xcode 4.2 に 2 つのコントローラー (最初、2 番目) があります。
最初のコントローラーにはテーブルビューがあり、ナビゲーションコントローラーに埋め込まれています。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 は、デフォルトのトランジションを持つモーダル セグエです。
秒.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];
概要:
「callback here」メッセージは表示されませんが、「委任された」メッセージが表示されます。「class:」デバッグ行は「null」を出力します。
なんで?
(これで最初から2番目に任意のデータを送信できますが、デリゲートのコールバックのみが機能しません)