私は委任の仕組みに従っていると思いますが、here's the tutorial I followedですが、どこかでうんざりしています。私はNSLogに代理人を期待していますが、そうではありません。誰が私が行方不明か間違っているかを知ることができますか?代表団の実装
マイMainViewController.h:
@interface MainViewController : UITableViewController <AddClassDelegate>
MainViewController.m:
- (void)cancelAddingClass {
NSLog(@"Canceled Yo");
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
/*
When a row is selected, the segue creates the detail view controller as the destination.
Set the detail view controller's detail item to the item associated with the selected row.
*/
if ([[segue identifier] isEqualToString:@"addClassSegue"]) {
UINavigationController *nc = (UINavigationController *)segue.destinationViewController;
AddClassViewController *addClassVC = (AddClassViewController *)[nc.viewControllers objectAtIndex:0];
addClassVC.delegate = self;
}
マイモーダルビューコントローラAddClassViewController.h:
@protocol AddClassDelegate <NSObject>
- (void)cancelAddingClass;
@end
@interface AddClassViewController : UITableViewController
@property (weak, nonatomic) id<AddClassDelegate> delegate;
- (IBAction)cancelButtonPressed:(id)sender;
AddClassViewController.m:
@synthesize delegate;
- (IBAction)cancelButtonPressed:(id)sender {
[self.delegate cancelAddingClass];
}
cancelButtonPressed:
は、ストーリーボードでのモーダルビューの[キャンセル]ボタンにフックアップされています。
これはうまくいくはずです... 'self.delegate cancelAddingClass'の前にNSLogの代理オブジェクトを試してみて、それがnullでないかどうかを確認してください。 – Shubhank
これは良くありません。私の代理人= null。 – tazboy
これはデリゲート宣言の弱い参照のためかもしれないと思います...強いものに変更しよう – Shubhank