在另一个类中使用 NSString
我只想从第二堂课的第一堂课访问 NSString 。
我在我的第一个类中使用了属性,这:
NSLog(@"The text is: %@", self.fileText);
在我的第一个类中返回正确的字符串。
但在我的第二堂课中,这个:
FirstViewController* controller = [[FirstViewController alloc] init];
NSLog(@"text: %@", controller.fileText);
返回(null)。
我正确导入了该类。 我可能做错了什么?
I simply want to access a NSString from my first class in my second class.
I used properties in my first class and this:
NSLog(@"The text is: %@", self.fileText);
returns the correct string in my first class.
But in my second class, this:
FirstViewController* controller = [[FirstViewController alloc] init];
NSLog(@"text: %@", controller.fileText);
returns (null).
I imported the class correctly.
What could I have done wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用这个
并检索第二个类中保存的数据,使用这个:
Use this
and to retrieve saved data in the second class, use this:
考虑到第二个类要么是第一个类的子类,要么只是该类的一个实例(这似乎更有可能)。
确保您在 FirstViewController 的 init 块中执行的操作,因为这就是第二个实现所调用的全部内容,如果您尚未在那里初始化字符串,则该值将为 null。是的,检查那里。
Considering the second class is either a sub-class of the first class or jus an instance of the class (which seems more likely).
Be sure what you are doing in your init block of the
FirstViewController
, because that's all that's being called for the second implementation and if you have not initialized your string there, the value will be null. So yep, check there.