individualPercUpdated
上调用 UIControlEventEditingDidEnd
,在checkInitialValue
调用UIControlEventEditingDidBegin
。通过发出警告Exec Bad Access
if(!([initialValue isEqualToString:textField.text]))
行崩溃
- (void)viewDidLoad
{
[super viewDidLoad];
initialValue=[[NSString alloc] init];
}
-(void) individualPercUpdated:(UITextField *)textField{
if(initialValue!=nil){
if(!([initialValue isEqualToString:textField.text])){
initialValue=textField.text;
NSLog(@"%@",textField.text);
}
}
else{
NSLog(@"%@",textField.text);
}
}
-(void) checkInitialValue:(UITextField *)textField{
initialValue=textField.text;
}
}
答案 0 :(得分:8)
将所有使用实例变量的属性替换为属性并通过它访问它,并且您不会对内存管理有任何问题。
@property (nonatomic, copy) NSString *initialValue;
...
@synthesize initialValue = _initialValue;
....
//Access with:
self.initialValue = @"something";