【问题标题】:Setting self.window.rootViewController causes SIGABRT设置 self.window.rootViewController 会导致 SIGABRT
【发布时间】:2011-07-03 17:21:54
【问题描述】:

我正在尝试做一个应用程序,您按下一个按钮,然后出现 UIAlertView,里面有一个 UIView 和 3 个自定义按钮。到目前为止一切正常。当我单击 3 个按钮之一时,我想更改 UIImageView 的图像,并且效果也很好。问题是,每次我尝试启动我的应用程序时,都会突然发生 sigabrt。

SIGABRT 发生在我的AppDelegate.m 这一行:

self.window.rootViewController = self.viewController;

如果有人可以帮助我,那就太好了,顺便说一下,我不太习惯 xcode 和 Objective-c,所以我不知道为什么会这样。

这是我的 viewController.h

#import UIKit/UIKit.h (i removed < > cause they were hiding everything inbetween in the post.)

@interface savingstatusViewController : UIViewController {

    UIView *loginView;
    UIImageView *statusImage;
    UIAlertView * MyTicketAlert;

}

- (IBAction)status:(id)sender;

@property (nonatomic, retain) IBOutlet UIView *loginView;    
@property (nonatomic, retain) IBOutlet UIImageView *statusImage;
@property (nonatomic, retain) IBOutlet UIAlertView * MyTicketAlert;

- (IBAction)green:(id)sender;
- (IBAction)yellow:(id)sender;
- (IBAction)red:(id)sender;

@end

这是我的 viewController.m

#import "savingstatusViewController.h"

@implementation savingstatusViewController

@synthesize loginView;
@synthesize statusImage,MyTicketAlert;

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

 #pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void)viewDidUnload
{
    [self setLoginView:nil];
    [self setStatusImage:nil];
    [super viewDidUnload];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return YES;
}

- (IBAction)status:(id)sender
{
    MyTicketAlert = [[UIAlertView alloc] initWithTitle:nil message:nil  delegate:self cancelButtonTitle:nil
                                     otherButtonTitles: nil];
    [MyTicketAlert addSubview:loginView];
    [MyTicketAlert show];
    MyTicketAlert.frame = CGRectMake(0, 1000, 440, 110);
}

- (IBAction)green:(id)sender 
{
    statusImage.image = [UIImage imageNamed:@"etat_controle.png"];

     [MyTicketAlert dismissWithClickedButtonIndex:0 animated:YES];
}

- (IBAction)yellow:(id)sender
 {
    statusImage.image = [UIImage imageNamed:@"etat_attention.png"];

     [MyTicketAlert dismissWithClickedButtonIndex:0 animated:YES];
}

- (IBAction)red:(id)sender
 {
    statusImage.image = [UIImage imageNamed:@"etat_danger.png"];

     [MyTicketAlert dismissWithClickedButtonIndex:0 animated:YES];
}

@end

【问题讨论】:

  • 初始化window和viewController的代码在哪里?请问可以发一下吗?
  • 我遇到了同样的问题 :(

标签: ios uiview uialertview sigabrt


【解决方案1】:

UIWindow rootViewController 属性在 iOS4 之前不存在。如果您尝试在装有 iOS 3 或更早版本的设备上运行此代码,它将崩溃。

在您的 AppDelegate 中,您可以改用 addSubview。

//self.window.rootViewController = self.viewController; // Only iOS >= 4
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
return YES;

【讨论】:

  • 或者,检查预处理器:“#if __IPHONE_OS_MIN_VERSION_REQUIRED>=__IPHONE_4_0”
  • 在互联网上找了大约 2 个小时。那里有很多废话,感谢 TumbleCow,第一次得到了惊人的答案。当在不同的 XCode 版本中工作时,这是一个真正的 gotu。另请注意,如果您使用的是较旧的 IOS 版本,请在 xcode 4 的构建设置中将 armv7 更改为 armv6。?。
【解决方案2】:

如果文件的所有者视图未设置或设置不正确,也会发生这种情况。确保您的 ViewController.xib 的 File's Owner 视图属性设置为您的视图。我花了一段时间才弄明白!

【讨论】:

    【解决方案3】:

    转到 MainWindow.xib 中的“TheNameOfYourProjetdelegate”。

    在“TheNameOfYourProjetdelegate”的“出口”中,您必须有 viewController,然后“控制拖动”到您的窗口并运行您的应用程序

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 2012-07-07
      • 1970-01-01
      • 1970-01-01
      • 2020-07-19
      • 1970-01-01
      相关资源
      最近更新 更多