2011-10-11 73 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.