lukegeiger / LGSemiModalNavController

A UINavigationController subclass that presents itself a dynamic amount in a view controller using the UIViewControllerAnimatedTransitioning protocol.
MIT License
409 stars 38 forks source link

Embedding MFMessageComposeViewController/ImagePicker #6

Closed emleeh closed 8 years ago

emleeh commented 8 years ago

Hi there, I'm trying to embed an MFMessageComposeViewController into the semi modals and it will not work. I keep getting an error saying I cannot push a Navigation Controller. This does not happen with any view controllers from the storyboard. It happens with the Image Picker too.

Is there any solution to this problem? Thank you!

lukegeiger commented 8 years ago

@emleeh Hey sorry to hear that, if you send me a sample project i'd be happy to debug it! lukejamesgeiger@gmail.com :)

emleeh commented 8 years ago

@lukegeiger That would be amazing, thank you!

This is the bones of the problem, but I'll put together a quick project and send it to you too so you can see.

`if (![MFMessageComposeViewController canSendText]) { NSLog(@"Message services are not available."); }else{

    MFMessageComposeViewController *composeVC = [[MFMessageComposeViewController alloc]init];
    composeVC.messageComposeDelegate = self;

    // Configure the fields of the interface.
    composeVC.recipients = @[@"14085551212"];
    composeVC.body = @"Hello from California!";

    LGSemiModalNavViewController *semiModal = [[LGSemiModalNavViewController alloc]initWithRootViewController:composeVC];
    //Make sure to set a height on the view controller here.
    semiModal.view.frame = CGRectMake(0, 0, self.view.frame.size.width, (self.view.frame.size.height/6)*5);

    //Selected customization properties, see more in the header of the LGSemiModalNavViewController
    semiModal.backgroundShadeColor = [UIColor blackColor];
    semiModal.animationSpeed = 0.35f;
    semiModal.tapDismissEnabled = YES;
    semiModal.backgroundShadeAlpha = 0.4;
    semiModal.scaleTransform = CGAffineTransformMakeScale(.94, .94);

    [self presentViewController:semiModal animated:YES completion:nil];
}

`

emleeh commented 8 years ago

@lukegeiger Also, it seems that viewDidAppear and viewDidLoad aren't called when the semi modal is dismissed. Is there any way of fixing this?

Thanks again!

lukegeiger commented 8 years ago

@emleeh Thanks so much for sending over the sample project! I have figured out what is going wrong.

  1. The LGSemiModalNavController is a UINavigationController subclass. And you are trying to wrap the MFMessageComposeViewController in a NavigationController, which is not allowed. You can check this yourself by substituting the LGSemiModalNavController with a regular UINavigationController. So in your use case I'm afraid what you are trying to do can't be achieved.
  2. For your second question, this is just how the view controller life cycle works in iOS. viewDidLoad is only going to get called once, when the view controller is initialized. In our case, we are never releasing the view controller from memory, and thus never re-initializing it again, so viewDidLoad will never get called again. As for viewWillAppear/viewDidAppear, again we are just presenting a vc over another, and the view behind is never actually disappearing, as it would with a navigation stack, so since it is not disappearing, it won't "re appear". You can achieve this same sort of affect programmatically however, if you set up some sort of delegate callback!
emleeh commented 8 years ago

Thank you so much for being so helpful. I really appreciate it. I figured out that question two was my fault alright, sorry about that!

Best of luck with everything and thanks again.

apascual commented 6 years ago

Hi,

One good solution for dealing with 2) is using:

[self.parentViewController beginAppearanceTransition:YES animated:YES];

On the completion block after the semi modal is dismissed, that way all the necessary view lifecycle methods will be automatically triggered.

Cheers.

lukegeiger commented 6 years ago

hey @apascual this repository is no longer maintained, but feel free to open up a pull request and i'll try to merge it in. thanks!