Objective c 与popToViewController共享数据
我的应用程序因此消息而崩溃Objective c 与popToViewController共享数据,objective-c,xcode,ios4,Objective C,Xcode,Ios4,我的应用程序因此消息而崩溃 011-02-22 00:12:30.422 test01[6246:207] -[RootViewController setString1:]: unrecognized selector sent to instance 0x623c800 2011-02-22 00:12:30.423 test01[6246:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentExcepti
011-02-22 00:12:30.422 test01[6246:207] -[RootViewController setString1:]: unrecognized selector sent to instance 0x623c800
2011-02-22 00:12:30.423 test01[6246:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[RootViewController setString1:]: unrecognized selector sent to instance 0x623c800'
*第一次抛出时调用堆栈:
这是我的代码:
- (void)save2:(id)sender{
(pseudoUtilisateur *) [pseudoUtilTb cellForRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0]];
self.string =textField.text;
NSLog(@"donnees %@",string);
AvisUtilisateur *avs = [self.navigationController.viewControllers objectAtIndex:0];
avs.string1 = self.string;
[self.navigationController popViewControllerAnimated:YES];
}
我不明白为什么它告诉我RootviewController setString1
thx这一行:
avs.string1 = self.string;
由编译器转换为:
[avs setString1:[self string]];
您将
avs
定义为AvisUtilisateur*avs
,因此假设根视图控制器(导航控制器视图控制器数组中索引0处的对象)是AvisUtilisateur
的实例。无论这是否正确,您的代码都假定根视图控制器具有名为string1
的readwrite
属性,显然情况并非如此。您好,谢谢您的回答。但我不明白为什么我必须在rootViewControll中声明string1。我不想在rootViewController中共享数据。可能是因为我使用了[self.navigationController.viewControllers]?我有3个类:rootViewController、AvisUtilisateur和PseudoUtilisateur。我想在PseudoUtilisateur和AvisUtilisateur之间共享数据。thxy您的代码正在向自定义类RootViewController
的实例发送setString1:
消息,该实例是导航控制器内索引0处的对象。也许您希望它是AvisUtilisatuer
的一个实例,但事实并非如此。