2013-12-13 70 views
0

我在我的代碼中出現訪問錯誤,我不明白爲什麼。 請儘快幫忙。 這裏是我的代碼得到一個EXC_BAD_ACCESS(code = 2,地址= 0x0)錯誤

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

PS:我創建了activeTextField財產在@interface,像這樣

@property (nonatomic,strong) UITextField *activeTextField;

和我合成它

@synthesize activeTextField;

+0

這是什麼'*(標籤)'? –

+0

它在哪一行打斷excaclty,什麼是*(tag)? –

+0

標記是UIView的一個屬性,@property(nonatomic)NSInteger * tag; – iOSMaster

回答

1

嘗試更換此行

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

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

爲了澄清@ Bhumeshwer的答案,在評估表達式前面放置一個星標將引用一個指針。由於標記最可能是一個整數(而不是指向整數的指針),因此解除引用會產生一些令人討厭的副作用。 –

+0

標籤是一個NSInteger不是int – iOSMaster

+0

@iOSMaster:'NSInteger'不是一個對象;它是32位或64位的int型typedef,具體取決於處理器。 –

相關問題