我正在尝试按下按钮,然后UIAlertView
出现,并且里面有一个UIView
,带有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
答案 0 :(得分:5)
在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;
答案 1 :(得分:4)
如果文件的所有者视图未设置或设置不正确,也会发生这种情况。确保ViewController.xib的File's Owner视图属性设置为您的视图。我花了一段时间才想出那一个!
答案 2 :(得分:2)
转到MainWindow.xib中的“TheNameOfYourProjetdelegate”。
在“TheNameOfYourProjetdelegate”的“outlet”中你必须有viewController,然后对你的窗口进行“控制拖动”并运行你的应用程序