我现在一直在处理这个(公认的简单)应用程序,这是我的第一个应用程序。这是一个选项卡式应用程序,但出于某种原因,当我点击另一个选项卡时它会崩溃。
日志中没有崩溃异常或原因,只显示 Thread 1 : Program Received Signal "SIGARBT"。
我开始使用 Interface Builder 但厌倦了它并删除了文件并改为使用 loadView,但是尽管清理了项目,我仍然遇到错误。 FirstViewController 使用完全相同的代码并且工作正常。
#import "SecondViewController.h"
@implementation SecondViewController
-(void)loadView
{
[self setView:[[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]]];
[[self view] setBackgroundColor:[UIColor blackColor]];
textField = [UITextField alloc];
[textField setEnablesReturnKeyAutomatically:YES];
[textField setKeyboardType:UIKeyboardTypeDefault];
[textField setSpellCheckingType:UITextSpellCheckingTypeNo];
[textField setFrame:CGRectMake(20, 30, 280, 40)];
[[self view] addSubview:textField];
setContextButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[setContextButton setTitle:@"Set" forState:UIControlStateNormal];
[setContextButton setFrame:CGRectMake(80, 30, 60, 40)];
[[self view] addSubview:setContextButton];
}
最佳答案
我认为 textField = [UITextField alloc];
行不完整。您需要在分配的文本字段上调用 init 方法之一。
假设您的 SecondViewController.h 已经定义了 UITextField *textField
,尝试:
textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 30, 280, 40)];
如果您没有定义 textField (这可能会导致其他问题,具体取决于您的其余代码的样子),请尝试:
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(20, 30, 280, 40)];
关于ios - 线程 1 : Program Received Signal "SIGABRT" iOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9676389/