1

I have a view controller with several textfields/text views and would like to allow the user to populate these fields with things they find on the web. To allow this I have a different web view presented modally. My problem is that I would like to use a partial page curl to display the first view controller (with any populated information). However, you can't present a live view controller a second time, and the new instance is not pre populated with whatever information was already placed in the textfields.

It seems like I could just pass that information back and forth (from the first instance, to the second view controller, then copy the info into the second instance, then copy back when I dismiss the second instance, etc) but it seems like there should be a better way.

I could also just add the web view controller as a subview, but I miss the functionality of the partial curl, which I really like.

Thanks!

Jbryson
  • 2,875
  • 1
  • 31
  • 53

2 Answers2

1

However, you can't present a live view controller a second time, and the new instance is not pre populated with whatever information was already placed in the textfields.

You dont need to create a new view controller each time. Just store that view controller object as an instance variable and dont release it until your user is done.

if (myViewController == nil) {
    myViewController = [UIViewController alloc] init];
}
[self presentViewController:myViewController animated:YES];    
Chris C
  • 3,221
  • 1
  • 27
  • 31
  • I had tried that, but you get this error: Application tried to present modally an active controller, since the controller is still active under the current controller. – Jbryson Feb 12 '13 at 21:28
  • You still need to call dismissViewController on your second view controller. If you're using ARC, your first viewcontroller will still have a reference to the second viewcontroller so it won't release it. If you're not using ARC, then just make sure you don't release the second view controller even when it's dismissed. – Chris C Feb 13 '13 at 20:02
  • But when you dismiss the presenting view controller, because the second controller was presented modally, the second controller gets dismissed. EG: controller_1 = modal segue => controller_2 (who dismisses controller_1 by calling [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];. This causes just controller1 to be shown, also we get Unbalanced calls to begin/end appearance transitions for .. in the debug area. – Jbryson Feb 13 '13 at 20:13
  • I mean you need to dismiss controller 2 when you go back to controller 1. – Chris C Feb 13 '13 at 22:51
0

So I've kind of combined the comments and the posted answer.

First: I store an instance of the vc with the web view and add its view to the first view controller and then hide the view:

self.webVC = [self.storyboard instantiateViewControllerWithIdentifier:@"webView"];
self.webVC.delegate = self;
self.webVC.view.frame = self.view.bounds;
[self.view addSubview:self.webVC.view];

[self.webVC.view didMoveToSuperview];
self.findPoemVC.view.hidden = YES;

Then I used a category on UIView to uncurl and curl the view. I found the code here:

To show the view I perform a CurlDown animation like this:

 self.findPoemVC.view.hidden = NO;
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0];
[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown
                       forView:self.webVC.view
                         cache:YES];

self.webVC.view.hidden = NO;
[UIView commitAnimations];

On the webVC I implemented a protocol and implement the delegate methods in the first view controller:

In the webVC:

@protocol PoemFinderDelegate <NSObject>
    -(void)shouldUncurl;
    -(void)doneWasPressed;
@end

The delegate was set earlier (see above) and the implementation of the delegate methods to partially uncurl and totally uncurl the webview were done like this inside the first view controller:

-(void)shouldUncurl{
    [self.webVC.view animationPartialCurlUp];
}
-(void)doneWasPressed{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.50];
    [UIView setAnimationTransition:UIViewAnimationTransitionCurlUp
                           forView:self.webVC.view
                             cache:YES];

    self.webVC.view.hidden = YES;
    [UIView commitAnimations];
}
Jbryson
  • 2,875
  • 1
  • 31
  • 53