不接收新值的字符串始终为(null)

时间:2010-11-29 12:51:34

标签: iphone objective-c cocoa-touch string null

这里发生了奇怪的事情。

NSString *string = [powerPickerVC.powerList objectAtIndex:selRow];
NSLog(@"powerPicker row = %@", string); //this returns me the string from powerList
repVC.selectedPower = string; //selectedPower doesn't receive the new value and returns (null)
NSLog(@"selectedPower = %@", repVC.selectedPower);

并且repVC.selectedPower始终返回(null)

就在那段代码之前,我有这个:

selectedRowPower = [powerPickerVC.powerPicker selectedRowInComponent:0];
repVC.selectedRowInObjectPicker = selectedRowPower;
NSLog(@"selectedRowInObjectPicker = %d", selectedRowPower);

这完美无缺。 selectedRowInObjectPicker是一个NSInteger但是如果我能够设置它的值,为什么我无法设置selectedPower的值?

是的,对象是合成的,一切......

3 个答案:

答案 0 :(得分:0)

您是否有机会定义了一个名为-setSelectedPower:的方法?

答案 1 :(得分:0)

repVC nil的可能性很高。尝试在那里添加断点并查看。

答案 2 :(得分:-1)

使用[NSString stringWithString:]初始化字符串。

在你的情况下,

repVC.selectedPower = [[NSString stringWithString:string];

确保接收器是正确声明的NSString。