gpt4 book ai didi

iphone - 调用方法时以编程方式创建的 UIButton 崩溃

转载 作者:行者123 更新时间:2023-11-28 18:13:47 24 4
gpt4 key购买 nike

我有一个 rootViewController 和一个以编程方式创建的 UIButton。我希望这个 UIButton 显示另一个 View Controller 。由于某种原因,它崩溃并出现以下错误:

Undefined symbols for architecture i386:
"_OBJC_CLASS_$_TutorialViewController", referenced from: objc-class-ref in RootViewController.o ld: symbol(s) not found for architecture i386 collect2: ld returned 1 exit status

这是创建信息 UIButton 的代码。此代码在 loadView 方法中:

 // Create a Button to get Help          
UIButton *helpButton = [UIButton buttonWithType:UIButtonTypeInfoDark ] ;
CGRect buttonRect = helpButton.frame;

// CALCulate the bottom right corner
buttonRect.origin.x = self.view.frame.size.width - buttonRect.size.width - 8;
buttonRect.origin.y = buttonRect.size.height - 8;
[helpButton setFrame:buttonRect];

[helpButton addTarget:self action:@selector(doHelp:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:helpButton];

}

这是转换到另一个 View Controller 的操作:

- (IBAction)doHelp:(id)sender{
NSLog(@"help button pressed");

TutorialViewController *sampleView = [[[TutorialViewController alloc] init] autorelease];
[sampleView setModalTransitionStyle:UIModalTransitionStyleFlipHorizontal];
[self presentModalViewController:sampleView animated:YES];
}

感谢您的帮助。

最佳答案

adig 可能是对的。

此外,从技术上讲,这不是“崩溃”。它“构建失败,出现此链接器错误。”您可以判断这是一个链接器错误,因为它说“ld 返回了 1 个退出状态”。 ld 是链接器。

在幕后,XCode 在运行之前编译并链接您的代码。如果在编译或链接过程中失败,那就是“构建失败”,而不是“崩溃”。崩溃是指应用程序已构建,但在运行时突然停止。一个常见的原因是访问了一个 nil 指针。

关于iphone - 调用方法时以编程方式创建的 UIButton 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9823449/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com