I am trying to do an application where you press a button then a UIAlertView
comes up and there is a UIView
inside it with 3 custom button. So far everything work. When i click on one of the 3 button i want to change the image of an UIImageView
and that works as well. The problem is that out of nowhere a sigabrt is now happening each time i try to start my apps.
The SIGABRT
happen in my AppDelegate.m
on this line:
self.window.rootViewController = self.viewController;
If somebody can help me that would be great and by the way im not very used to xcode and objective-c so i don't have a clue why this is happening.
Here is my 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
Here is my 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
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;