执行错误访问NSString

时间:2012-07-05 06:39:35

标签: iphone ios nsstring uitextfield exc-bad-access

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;
    }

}

1 个答案:

答案 0 :(得分:8)

将所有使用实例变量的属性替换为属性并通过它访问它,并且您不会对内存管理有任何问题。

@property (nonatomic, copy) NSString *initialValue;
...
@synthesize initialValue = _initialValue;
....
//Access with:
self.initialValue = @"something";