简体   繁体   English

属性值未传递给其他方法

[英]property value not getting passed to other method

In my header file I declared a new property like this: 在我的头文件中,我声明了一个新属性,如下所示:

@property (weak, nonatomic) NSString *porperty;

In my implementation file I give the property a value: 在我的实现文件中,给该属性一个值:

-method1{
 self.property = someString;
 NSLog(@"property = %@", self.property);
}

The log shows up in the debugger as the same value of someString. 日志在调试器中显示为someString的相同值。 Okay great, but when i try to use this property in the next method of the same implemtation file it loses its value. 好的,但是当我尝试在同一实现文件的下一个方法中使用此属性时,它将失去其值。

-method2{
 NSLog(@"property = %@", self.property);
}

Now the debugger says (null). 现在调试器说(空)。

Simple question. 简单的问题。 i know but this usually works for me. 我知道,但这通常对我有用。 What am i doing wrong? 我究竟做错了什么?

This is because someString has been released on next cycle. 这是因为someString已在下一个周期释放。 Replace weak by strong, this will retain your string. 用强替换弱,这将保留您的字符串。

@property (strong, nonatomic) NSString *porperty; @属性(强的,非原子的)NSString *属性;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM