我正在尝试做一个应用程序,你按下一个按钮,然后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;