Matthew Olivan
Matthew Olivan

Reputation: 45

Warning: Attempt to present <UIViewController: 0x74acff0> on <ViewController: 0x82b25a0> whose view is not in the window hierarchy

I am new to objective c programming and i'm making an app. I am using osx 10.8.4 and xcode 4.6. I am trying to (modal)segue from one view controller to another in a single-view application. I have already given the segue identifier for the segue and put a segue in the storyboard. However, when i try to segue the console shows this:

 Warning: Attempt to present <UIViewController: 0x74acff0> on <ViewController: 0x82b25a0> whose view is not in the window hierarchy!

Here is my code for my first view controller .m file(contains code to segue):

 Viewcontroller.m:

 #import "ViewController.h"
 #import "hackScreen.h"
 #import "AppDelegate.h"
 #import <RevMobAds/RevMobAds.h>

 @interface ViewController ()

 @end

 @implementation ViewController

 - (void)viewDidLoad
 {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.

}


- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
 }

- (IBAction)hackStarter:(id)sender {

NSString *checker = [_redBoulderRepublic text];
int soLong = [checker length];

UIAlertView *wrongNumber = [[UIAlertView alloc]
                            initWithTitle:@"Invalid number"
                            message:@"Please enter a valid phone number"
                            delegate:nil
                            cancelButtonTitle:@"dismiss"
                            otherButtonTitles:nil];

if (soLong == 10){
    [self performSegueWithIdentifier:@"SegueOne" sender:sender];

}
else{
   [wrongNumber show]; 
}

 }
 - (void)dealloc {
[_redBoulderRepublic release];
[super dealloc];
}
 - (IBAction)keyboardKiller:(id)sender {
[_redBoulderRepublic resignFirstResponder];
 }



@end

And my .h file:

 Viewcontroller.h:

#import <UIKit/UIKit.h>
#import <RevMobAds/RevMobAds.h>
#import "AppDelegate.h"
#import "hackScreen.h"
@interface ViewController : UIViewController
- (IBAction)hackStarter:(id)sender;
@property (retain, nonatomic) IBOutlet UITextField *redBoulderRepublic;
- (IBAction)keyboardKiller:(id)sender;


@end

Upvotes: 2

Views: 3377

Answers (1)

rmaddy
rmaddy

Reputation: 318944

The error means that your ViewController isn't currently displayed but you are trying to perform a segue to another controller. In order to perform a transition from one view controller to another, the first view controller needs to be visible (or at least added to the view hierarchy).

In other words, you are calling hackStart before the instance of ViewController has been displayed.

Upvotes: 4

Related Questions