获得EXC_BAD_ACCESS(代码= 2,地址= 0x0)错误

时间:2013-12-13 20:46:59

标签: ios objective-c exc-bad-access

我的代码中出现了错误的访问错误,我不知道为什么。

这是我的代码

-(IBAction)datePickerValueChanged:(UIDatePicker *)sender{
    myDatePicker = [[myDatePickerView subviews] lastObject];
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setLocale:sender.locale];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    activeTextField = (UITextField *) [self.view viewWithTag: *(tag)];
    [activeTextField setText:[dateFormatter stringFromDate:[sender date]]];
}

P.S:我在@interface中创建了activeTextField属性,就像这样

@property (nonatomic,strong) UITextField *activeTextField;

我合成了它

@synthesize activeTextField;

1 个答案:

答案 0 :(得分:1)

尝试替换此行

activeTextField = (UITextField *) [self.view viewWithTag: *(tag)];

activeTextField = (UITextField *) [self.view viewWithTag: tag];//tag should be an integer