7

我正在尝试做一个应用程序,你按下一个按钮然后UIAlertView出现一个,里面有一个UIView带有 3 个自定义按钮的应用程序。到目前为止一切正常。当我单击 3 个按钮中的一个时,我想更改 an 的图像,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
4

3 回答 3

5

The UIWindow rootViewController property doesn't exist before iOS4. If you're trying to run this code on an device with iOS 3 or older, it will crash.

In your AppDelegate, you can use addSubview instead.

//self.window.rootViewController = self.viewController; // Only iOS >= 4
[self.window addSubview:self.viewController.view];
[self.window makeKeyAndVisible];
return YES;
于 2011-07-06T14:21:20.243 回答
4

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

于 2011-08-13T14:07:49.750 回答
2

转到 MainWindow.xib 中的“TheNameOfYourProjetdelegate”。

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

于 2011-04-06T22:36:05.567 回答