0

i started a single view template in Xcode 4.2(recently upgraded to Xcode 4.2 and ios5)

so now i have only one view controller.

I added a new class to the project which is a subclass of UIViewcontroller.

Now in the main controller class viewdidLoad method

- (void)viewDidLoad
{

    // Override point for customization after application launch.
    [super viewDidLoad];
    [self presentQuizcontroller];
}
-(void) presentQuizcontroller
{
    _QuizController = [[[Quiz alloc] initWithNibName:@"Quiz" bundle:nil] autorelease];
    _QuizController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:_QuizController animated:YES];        // Do any additional setup after loading the view, typically from a nib.

}

the problem is in my Quiz class

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

the initWithNibName method does get called(i checked by using breakpoint) but it doesn't passes the condition of if(self) . and hence the view don't appears.

Any ideas?

Edit

After the first answer i tried this way too

- (void)viewDidLoad
{

    // Override point for customization after application launch.
        [super viewDidLoad];
}
-(void) presentQuizcontroller
{
    _QuizController = [[[Quiz alloc] initWithNibName:@"Quiz" bundle:nil] autorelease];
    _QuizController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
    [self presentModalViewController:_QuizController animated:YES];        // Do any additional setup after loading the view, typically from a nib.

}
-(void) awakeFromNib
{
    [self presentQuizcontroller];

}

same thing Quiz.m initwithnib name method does not passes the condition if(self).

Shubhank
  • 21,721
  • 8
  • 65
  • 83

2 Answers2

0
  1. PresentModalViewController is depreciated, I think you should now use presentViewController instead of it.

  2. Are you sure that "Quiz" is the name of your file? That string should be same as the name of your xib file, namely something like "QuizController" or "QuizViewController"

  3. Make sure the xib file is properly connected to header/implementation files by checking:

    • Owner of the xib file should be set as the viewController

    • View on the xib file (the one above all if you have multiple views) should be connected to viewControllers view.

Yunus Nedim Mehel
  • 12,089
  • 4
  • 50
  • 56
0

I think you need to use awakefromnib.

Here is the Link for another StackOverflow post if you want to read more.

Community
  • 1
  • 1
k-thorat
  • 4,873
  • 1
  • 27
  • 36