我试图实现委托设计模式。无法传递数据到前一个视图控制器
我有两个视图控制器作为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 –