2011-10-11 63 views
0

同時運行iPhone仿真,顯示了針對 「EXC_BAD_ACCESS」 錯誤在Xcode「EXC_BAD_ACCESS」在Xcode

代碼如下:

Test.h

@interface Test : UIViewController 
{ 
    int iWeight; 
} 

end 

Test.m

@implementation Test 

- (void)viewDidLoad 
{ 
    iWeight = 15; 
} 

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 
{ 

    **NSLog(@"integer Number is :%@", iWeight); // error occur** 

} 

如果我點擊UIAlertView的按鈕,Xcode出現「EXC_BAD_ACCESS」錯誤代碼

我不知道爲什麼代碼出現錯誤。幫我。

+0

EXC_BAD_ACCESS意味着你傳遞一個錯誤的指針地方。你需要找出哪一行代碼導致它,然後找出你正在做什麼來傳遞一個糟糕的指針。在格式化方法中傳遞一個指針所期望的整數是一種情況,但還有很多其他情況。 –

回答

3

嘗試NSLog(@"integer Number is :%d", iWeight);

0
yes, try this 

NSLog(@"wieght is %d",iweight); 

%d type specifier for int iweight; 

and also set property in .h file and synthesize it in .m file. 

if it dont work then try this 
remove your alertview method 

write this 


// .h file 
-(IBAction)buttonClicked; 

// .m file 
-(IBAction)buttonClicked 
{ 
    NSLog(@"weight %d",iweight"); 
} 

right click of button and assign TouchUpInside to buttonClicked method. 
相關問題