Gary
Gary

Reputation: 25

presentModalViewController inside UIViewController class

View *view1 = [[View alloc] init];  
[self presentModalViewController:view1 animated:YES];

The code above works when connected to a UIButton. It does not work upon launch of an application by putting it in the viewDidLoad: method. I would like to run this upon launch.

Upvotes: 1

Views: 946

Answers (2)

letsdev-cwack
letsdev-cwack

Reputation: 139

Since iOS 6 you should use following method, because of deprections:

MyViewController* myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil]; [self presentViewController:myViewController animated:YES completion:nil];

Upvotes: 0

Shaggy Frog
Shaggy Frog

Reputation: 27601

Look very closely at the method you're calling: presentModalViewController: presents a controller, not a view.

The correct pattern is something like this:

MyViewController* myViewController = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
[self presentModalViewController:myViewController animated:YES];
[myViewController release];

Upvotes: 5

Related Questions