ios - 线程 1 : Program Received Signal "SIGABRT" iOS

标签 ios

我现在一直在处理这个(公认的简单)应用程序,这是我的第一个应用程序。这是一个选项卡式应用程序,但出于某种原因,当我点击另一个选项卡时它会崩溃。

日志中没有崩溃异常或原因,只显示 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/

相关文章:

iOS:举起聆听

ios - 如何使 UICollectionView 通过自动调整大小来填充其 super View ?

ios - 将导入的类设置为委托(delegate)

objective-c - ios设置屏幕用户界面

ios - iOS 中的 ADSR,示例代码?

ios - iOS 中的 WKWebView : How can I intercept a click and retrieve the linked content instead?

ios - 无法理解 fetchRequest.predicate

ios - block 内返回

iphone - 如何检测Game Center支持?

ios - 使用自动布局自动调整表格单元格大小不起作用