Setting self.window.rootViewController causes SIGABRT
Asked Answered
S

3

7

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
Savoie answered 24/2, 2011 at 16:45 Comment(2)
Where is the code for initializing the window and viewController? Can you post that, please?Exhale
I am getting the same issue :(Ulund
A
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;
Arnhem answered 6/7, 2011 at 14:21 Comment(2)
Or, check with preprocessor: "#if __IPHONE_OS_MIN_VERSION_REQUIRED>=__IPHONE_4_0"Saturation
Been looking for this for about 2 hours on the internet. There is so much crap out there, amazing answer worked first time thanks TumbleCow. This is a real gotu when working in different XCode versions. Also be aware that if you are working with older IOS versions change the armv7 to armv6 in your build settings in xcode 4.?.Trimurti
S
4

This also happens if the file's owner view has not been set or set incorrectly. Ensure the File's Owner view property of your ViewController.xib is set to your view. Took me a while to figure that one out!

Saidee answered 13/8, 2011 at 14:7 Comment(0)
N
2

go to "TheNameOfYourProjetdelegate" in MainWindow.xib.

In "outlets" of "TheNameOfYourProjetdelegate" you must have viewController, then do a "control drag" to your window et run your application

Nerin answered 6/4, 2011 at 22:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.