Search code examples
iosuipopovercontrolleralloc

Crash when I try to alloc a UIPopoverController


Hi I am at my wits end with what I am doing wrong here. Has anyone experienced anything similar? I checked the apple developer forums, google, stack overflow and couldn't find anything.

MyViewController *myView;
myView = [[MyViewController alloc] initWithNibName:@"MyViewController" bundle:nil];
//or myView = [[MyViewController alloc]init];
UIPopoverController *popover;
popover = [[UIPopoverController alloc] initWithContentViewController:myView];  //always crash at here
//i've tried with some others ViewController but it's still crash.

Thanks so much.


Solution

  • Assuming you're developing for iPad, try to give the popOver some frames, and try also to resize MyViewController nib, otherwise when it tries to load the view, it can't 'cause it's too big!

    Something like

    CGSizeMake(MyViewController.view.frame.size.width, MyViewController.view.frame.size.height);
    

    Remember to resize it though