【问题标题】:“EXC_BAD_ACCESS” in XcodeXcode 中的“EXC_BAD_ACCESS”
【发布时间】:2011-10-11 15:43:53
【问题描述】:

在运行 iphone 模拟时,我在 Xcode 中显示“EXC_BAD_ACCESS”的错误

代码如下:

测试.h

 @interface Test : UIViewController
 {
   int iWeight;
 }

end

测试.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”错误

我不知道为什么该代码会出现错误。帮帮我。

【问题讨论】:

  • EXC_BAD_ACCESS 表示您在某处传递了错误的指针。你需要弄清楚是哪一行代码导致了它,然后弄清楚你在做什么来传递一个错误的指针。在格式方法中传递一个需要指针的整数是一种情况,但还有很多其他情况。

标签: iphone objective-c xcode cocoa-touch


【解决方案1】:

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

【讨论】:

    【解决方案2】:
    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.
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-26
      • 2010-12-09
      • 2020-02-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多