iphone - 调试 iPhone 应用程序

标签 iphone debugging ios

如何调试 iPhone 应用程序?我怎样才能知道模拟器中发生了什么?我是Xcode开发的初学者,不知道下面的代码有什么问题。单击按钮时应用程序崩溃。

- (void)viewDidLoad {

    myLabel = [[UILabel alloc]init];

    [myLabel setText:@"Labela"];
    myLabel.frame = CGRectMake(50.0,50.0, 100.0, 30.0);
    [self.view addSubview:myLabel];

    myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

    [myButton addTarget:self 
                 action:@selector(buttonAction:)
       forControlEvents:UIControlEventTouchDown];

    [myButton setTitle:@"Klikni" forState:UIControlStateNormal];
    [myButton setFrame:CGRectMake(80.0, 210.0, 160.0, 40.0)];

    [self.view addSubview:myButton];
    [super viewDidLoad];

}

- (void)buttonAction {
    [myLabel setText:@"Promijenjen!"];
}

最佳答案

action:@selector(buttonAction:)

在这里您指定 buttonAction 选择器获取 1 个参数,但它被声明为没有:

- (void)buttonAction{
...

所以当按钮点击系统试图调用未定义的方法并导致崩溃。要解决这个问题,您应该将选择器名称更改为

action:@selector(buttonAction)

或更改操作方法声明:

- (void)buttonAction:(id)sender{
    ...

关于iphone - 调试 iPhone 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3821853/

相关文章:

iphone - 图片不会加载到UIImageView iPhone应用程序中

iphone - 在 iphone 应用程序中录制用户语音时降低噪音?

c++ - 尝试调试 TensorFlow C++ 代码时 GDB 退出/崩溃

将 lisp 字符串转换为 C 语言中的树 - 程序崩溃但在 Debug模式下运行

ios - 如何将 UPC-A 转换为 UPC-E?

iphone - 如何围绕对角线旋转 CALayer?

c# - 调试时 Visual Studio 2013 变量值不正确

ios - 执行自动转场

ios - 在 Swift 的 MVVM 中处理 subview 中的事件

ios - 在 iOS 上扫描蓝牙 2.1(旧版)设备