如何从另一个类设置 NSString* 属性?
请看下面的代码。
FirstViewController.h:
@interface FirstViewController : UIViewController {
NSString* inputData;
}
@property (nonatomic, copy/retain) NSString* inputData;
FirstViewController.m:
@synthesize inputData;
SecondViewController.m:
- (IBAction)buttonSaveDown {
[firstViewController setInputData:@"Text"];
firstViewController.inputData = @"Text";
firstViewController.inputData = [[NSString stringWithString:@"Text"] retain];
}
在每行带有 inputData 的后面添加断点。检查firstViewController.inputData - 它是“(null)”!为什么?
Printing description of inputData:
(null)
我还尝试在调试器中“编辑值”。设置值后,结果也是“(null)”。
构建时没有任何警告。请帮助任何人。多谢!
致版主:抱歉,当我要求删除之前的问题的所有评论时,有人删除了该问题。
Please look to the following code.
FirstViewController.h:
@interface FirstViewController : UIViewController {
NSString* inputData;
}
@property (nonatomic, copy/retain) NSString* inputData;
FirstViewController.m:
@synthesize inputData;
SecondViewController.m:
- (IBAction)buttonSaveDown {
[firstViewController setInputData:@"Text"];
firstViewController.inputData = @"Text";
firstViewController.inputData = [[NSString stringWithString:@"Text"] retain];
}
Add breakpoints after every line with inputData. Check firstViewController.inputData - it's '(null)'! Why?
Printing description of inputData:
(null)
Also I try 'Edit value' in the debugger. After setting value the result is '(null)' too.
There's no any warnings on the build. Please help anybody. Thanks a lot!
To moderators: Sorry, but someone deleted the same previous question when I asked to delete all comments on it.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的
firstViewController
变量未设置任何内容。您需要将其设置为 FirstViewController 的有效实例,然后才能使用它执行任何有用的操作。Your
firstViewController
variable is not set to anything. You need to set it to a valid instance of FirstViewController before you can do anything useful with it.只需使用
然后这些都应该起作用:
Just use
Then these each should work: