user141302
user141302

Reputation:

Why isn't presentModalViewController working?

I coded in button action like:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:mainDelegate.window cache:NO];
[mainDelegate.window addSubview:[self.calcentryController view]];
[UIView commitAnimations];

It works fine, but when I use in calcentryController.m in one action:

[self presentModalViewController:self.weeklyScoreController animated:YES];

to go to another viewcontroller, it is not working.

Upvotes: 1

Views: 2843

Answers (4)

Rajavanya Subramaniyan
Rajavanya Subramaniyan

Reputation: 2155

If you have a deep hierarchy of view controllers' views subviewed into one another, then always try to present with immediately viewcontroller whose view is directly added to the window of ur iphone app.

For e.g. I had 4 levels of view like window > vc1's view > vc2's view > vc3's view

So when I tried to call [vc3 presentModalViewController] it was not working.. I had to present with vc1 and it worked. I had vc1 referenced as a property to app delegate and hence was able to access easily.

But again, I didn't still find the actual reason, but I can say this worked for me.

Upvotes: 0

zlog
zlog

Reputation: 3316

I could be because your code is in viewDidLoad instead of viewDidAppear as per presentModalViewController does nothing

I had the same issue.

Upvotes: 0

Malaxeur
Malaxeur

Reputation: 6043

It's possible that your weeklyScoreController is nil. I'm not sure where you create it, since the code block is not pasted but that's a common mistake I see.

Upvotes: 0

Ed Marty
Ed Marty

Reputation: 39690

Is there any reason you aren't using presentModalViewController for calcentryController? You can set modalTransitionStyle on calcentryController to UIModalTransitionStyleFlipHorizontal and just use presentModalViewController:animated instead of doing manual animations.

The reason this may help is because your code is not calling certain functions like viewWillAppear:, viewDidAppear:, etc., whereas presentModalViewController:animated calls all the right functions for presenting new views.

Upvotes: 0

Related Questions