微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

ios – 设置self.window.rootViewController会导致SIGABRT

我正在尝试做一个应用程序,你按下一个按钮,然后UIAlertView出现,里面有一个UIView,带有3个自定义按钮.到目前为止一切正常.当我点击其中一个按钮时,我想要更改UI ImageView的图像,这也是有效的.问题是,每当我尝试启动我的应用程序时,就会出现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

解决方法

在iOS4之前,UIWindow rootViewController属性不存在.如果您尝试在iOS 3或更高版本的设备上运行此代码,则会崩溃.

在AppDelegate中,您可以使用addSubview.

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

原文地址:https://www.jb51.cc/iOS/331795.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐