【发布时间】:2012-03-20 20:37:49
【问题描述】:
这是使用引用计数 (ARC) 的 iOS 程序中类定义的一部分:
@interface CapViewController : UIViewController
{
NSString *bottomBn;
NSString *topBn;
}
@property (nonatomic, strong) NSString *bottomBn;
@property (nonatomic, strong) NSString *topBn;
@end
在实现中我综合了它们:
@implementation CapViewController
@synthesize bottomBn;
@synthesize topBn;
问题是当我尝试分配值时。如果我在类方法中逐步执行以下几行(第一次使用每个实例变量):
bottomBn = [NSString stringWithString:@"bottomBn"];
topBn = [NSString stringWithString:@"topBn"];
第一行执行后,topBn 的值变为@"bottomBn",bottomBn 为 nil 第二行没有影响。
如果我更改了在类中定义实例变量的顺序,即:
NSString *topBn;
NSString *bottomBn;
那么第一个赋值无效,第二个赋值导致“topBn”被赋值给bottomBn。
使用局部变量,它按预期工作:
NSString *localbottomBn = [NSString stringWithString:@"defaultbottombutton"];
NSString *localtopBn = [NSString stringWithString:@"defaulttopbutton"];
这对我来说似乎很奇怪。如有任何帮助,我将不胜感激。
【问题讨论】:
-
你能在你设置它们的行周围发布更多代码吗?如果你可以发布一个完整的、最小的测试用例来重现问题,那也会有所帮助。
-
当前版本的 lldb 在显示 ivars 值方面存在严重错误。见stackoverflow.com/questions/9533189/… 和stackoverflow.com/questions/9408219/…
标签: objective-c ios nsstring