0

Regarding transitionFromView:toView:duration:options:completion: Apple doc says this in last few lines:

This method modifies the views in their view hierarchy only. It does not modify your application’s view controllers in any way. For example, if you use this method to change the root view displayed by a view controller, it is your responsibility to update the view controller appropriately to handle the change.

If a ViewController has 2 full screen size views display one at a time then no issues:

[transitionFromView:self.view toView:self.view2...

but what this means it is your responsibility to update the view controller appropriately to handle the change?

if I do this:

secondViewController *sVc = [[secondViewController alloc]init];
[transitionFromView:self.view toView:sVc.view...

how its my responsibility to update the view controller appropriately to handle the change? or how to update ViewController?

UPDATE

I created a single view projec, add secondVC then in firstVC on button tap i did this:

self.svc = [[secondVC alloc]init]; 

[UIView transitionFromView:self.view toView:self.svc.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {}];

... secondVC viewDidLoad is working its nslog is working.

Then how to handle updating of viewcontroller?

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
S.J
  • 3,063
  • 3
  • 33
  • 66

2 Answers2

2

The statement "it is your responsibility to update the view controller appropriately to handle the change." it meant that you have to appropriately call view hierarchy delegate methods such as:

- (void)viewDidLoad;
- (void)viewDidUnload;
- (void)viewWillAppear;
- (void)viewDidDisappear;

And other methods that are responsible for proper view management.

Here are some examples.

Community
  • 1
  • 1
art-divin
  • 1,635
  • 1
  • 20
  • 28
  • I created a single view project just add secondVC then in firstVC on button tap i did this self.svc = [[secondVC alloc]init]; [UIView transitionFromView:self.view toView:self.svc.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {}]; ... secondVC viewDidLoad is working its nslog is working. – S.J May 03 '13 at 05:22
  • but have you tried to put NSLog to -viewWillAppear; -viewDidAppear etc.? There is no guarantee that -viewDidLoad will be called because you are not actually pushing UIViewController into navigation stack – art-divin May 03 '13 at 09:26
  • please view update in my question, -viewWillAppear; -viewDidAppear all are working perfectly fine. – S.J May 03 '13 at 10:42
  • can you publish your test project to github repository? It seems strange for me because one cannot get callbacks if the UIViewController is not in some kind of navigation stack – art-divin May 03 '13 at 12:43
  • Please visit this link I have uploaded the test project here https://anonfiles.com/file/521cbb41b086eae987fe27eb98278aba – S.J May 06 '13 at 04:21
  • Please visit this link I have uploaded the test project so you'll be able to accept my answer *hopefully* - it's pretty clear - the difference - between our test projects: https://anonfiles.com/file/5ac22c4d73f4a20c561c5859dc8795f5 – art-divin May 06 '13 at 08:34
  • Have no idea. Researched a lot in reference but couldn't find any solutions. I am investigating into that. But I've shown you the point of the answer - if you add root view controller into some kind of view hierarchy and if you don't make this view controller the rootViewController of the window - then callbacks aren't being called – art-divin May 06 '13 at 09:48
  • I will expand the answer later, but you've got the point, right? – art-divin May 06 '13 at 09:55
  • In your app delegate just add firstVC to rootViewController not navigation controller and all methods will start working :) – S.J May 06 '13 at 10:11
  • As I already pointed that out already in my previous comments, this is what is meant by that statement in reference documentation. You've asked for this exactly, I've explained enough. – art-divin May 06 '13 at 10:42
  • I would like to invite you to answer this question http://stackoverflow.com/questions/17657719/please-clear-some-confusions-regarding-uiviewcontroller – S.J Jul 16 '13 at 05:23
1

When we use transitionFromView:toView:duration:options:completion: we are only bringing toView up in view hierarchy. but Apple says we should handle updating of ViewControllers which are parent of these views.

Maintaining viewcontroller in navigationcontroller stack...

For .ex: if You have TabController in your application,

somewhere at tabIndex two you required to show view of viewcontroller at tabindex 1, then you should update your tabIndex when you will use transitionfromview method

[UIView transitionFromView:fromView 
                        toView:toView 
                      duration:0.5 
                       options:(controllerIndex > tabBarController.selectedIndex ? UIViewAnimationOptionTransitionCurlUp : UIViewAnimationOptionTransitionCurlDown)
                    completion:^(BOOL finished) {
                        if (finished) {
                            tabBarController.selectedIndex = controllerIndex;
                        }
                    }];
BhushanVU
  • 3,455
  • 1
  • 24
  • 33
  • I created a single view project just add secondVC then in firstVC on button tap i did this self.svc = [[secondVC alloc]init]; [UIView transitionFromView:self.view toView:self.svc.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {}]; ... secondVC viewDidLoad is working its nslog is working. – S.J May 03 '13 at 05:22
  • I would like to invite you to answer this question http://stackoverflow.com/questions/17657719/please-clear-some-confusions-regarding-uiviewcontroller – S.J Jul 16 '13 at 05:23