未接收新值的字符串始终为 (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
的值?
是的,物体被合成了,一切......
Weird thing is happening here.
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);
And repVC.selectedPower is always returning (null)
!
Just before that piece of code, I have this:
selectedRowPower = [powerPickerVC.powerPicker selectedRowInComponent:0];
repVC.selectedRowInObjectPicker = selectedRowPower;
NSLog(@"selectedRowInObjectPicker = %d", selectedRowPower);
And that works perfectly. selectedRowInObjectPicker
is an NSInteger but if I'm able to set its value, why am I not being able to set selectedPower
's value?
Yes, the object is synthesized and everything...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
repVC
很有可能是nil
。尝试在那里添加断点看看。High chance that
repVC
isnil
. Try to add breakpoint there and see.您是否定义了一个名为
-setSelectedPower:
的方法?Have you defined a method called
-setSelectedPower:
by any chance?使用 [NSString stringWithString: ] 初始化字符串。
在你的情况下,
repVC.selectedPower = [[NSString stringWithString:string];
并确保接收者是按预期正确声明的 NSString。
Use the [NSString stringWithString: ] to initialize strings.
In your case,
repVC.selectedPower = [[NSString stringWithString:string];
And ensure the receiver is a properly declared NSString as intended.