我試圖實現委託設計模式。無法傳遞數據到前一個視圖控制器
我有兩個視圖控制器作爲followsm
- CallViewViewController
- CEPeoplePickerNavigationController
這是CallViewViewController
@interface CallViewViewController()<CEPeoplePickerNavigationControllerDelegate>{
}
@property(nonatomic)CustomMessageClass * customMessageClassObject;
@end
我在執行我的接口定義,我有OF-課程實施委託方法
-(void)cePeoplePickerNavigationController:(CEPeoplePickerNavigationController *)peoplePicker didFinishPickingPeople:(NSArray *)peopleArg values:(NSDictionary *)valuesArg
{
NSLog(@"can populate the tableview");
}
這是我的第二類的接口定義,
@protocol CEPeoplePickerNavigationControllerDelegate;
@interface CEPeoplePickerNavigationController : UIViewController <UITableViewDelegate,UITableViewDataSource>{
id<CEPeoplePickerNavigationControllerDelegate> peoplePickerDelegate;
ABAddressBookRef addressBook;
}
@property (nonatomic, assign) id<CEPeoplePickerNavigationControllerDelegate> peoplePickerDelegate;
@property (nonatomic, retain) CEPeoplePickerNavigationController *ppnc;
@end
@protocol CEPeoplePickerNavigationControllerDelegate <NSObject>
- (void)cePeoplePickerNavigationController:(CEPeoplePickerNavigationController *)peoplePicker didFinishPickingPeople:(NSArray*)people values:(NSDictionary *)values;
@end
當用戶按下提交按鈕時,林執行以下代碼,
if ([self.ppnc.peoplePickerDelegate respondsToSelector:@selector(cePeoplePickerNavigationController:didFinishPickingPeople:values:)])
[self.ppnc.peoplePickerDelegate cePeoplePickerNavigationController:self.ppnc didFinishPickingPeople:sortedPeople values:[NSDictionary dictionaryWithDictionary:self.selectedValues]];
但數據沒有被傳回給前一個視圖控制器。爲什麼這樣?
UPDATE
我嘗試下面的代碼首先移動形式第二視圖控制器,
CEPeoplePickerNavigationController *nextVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PeoplePickerNavigationController"];
nextVC.peoplePickerDelegate = self;
[self presentViewController:nextVC animated:YES completion:nil];
但它引發以下錯誤,
終止應用程序由於未捕獲的異常' NSInvalidArgumentException',原因:' - [UINavigationController setPeoplePickerDelegate:]:無法識別的選擇器發送到實例0x101054800'
您的第一個視圖控制器是否接受委託? –
不...第一個視圖控制器委託不被稱爲 –
我使用instantiateViewControllerWithIdentifier –