Search code examples
objective-cmodalviewcontroller

ModalViewController not presenting on button press


I have this ViewController with on it a UIButton. This button fires a method and this should present a modalVC in his place. Yet for some reason it's not working anymore. I've been using the same code before without any issues but yet it bugs me.

-(void)showModalVC //the method that's being fired by the button.
{
    NSLog(@"modalVC to create a table"); //this log is being printed so the button fires as proper.

    self.myModalVC = [[MyModalViewController alloc] init]; //a local var gives same results.

    self.myModalVC.dismissDelegate = self; //the delegate is handled as proper.

    UINavigationController *navController = [[UINavigationController alloc]
                                             initWithRootViewController:self.myModalVC];

    //navController.modalPresentationStyle = UIModalPresentationFormSheet;

    [self presentModalViewController:navController animated:YES];

    [self.myModalVC release];
    [navController release];
}

What could be a reason for a ModalVC not to pop over my current view from where ever it is called?

I've been using this very same method before (in other projects in other contexts) so I'm dazzled it hasn't been working yet. The method is fired and it passes every line of code without crash.

If you have an idea. post it here. Thanks.


Solution

  • -(void)showModalVC
    {
        self.myModalVC = [[ModalVC alloc] init];
    
        self.myModalVC.dismissDelegate = self;
    
        UINavigationController *navController = [[UINavigationController alloc]
                                                 initWithRootViewController:self.myModalVC];
    
        navController.modalPresentationStyle = UIModalPresentationFormSheet; //or something similar, this one is used on an iPad
    
        UILabel *navTopItemTitle = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 44)];
        navTopItemTitle.text = @"Modal shizzle";
        navTopItemTitle.backgroundColor = [UIColor clearColor];
        navTopItemTitle.textColor = [UIColor whiteColor];
        navTopItemTitle.textAlignment = UITextAlignmentCenter;
    
        [navController.navigationBar.topItem setTitleView:navTopItemTitle];
    
        [self presentModalViewController:navController animated:YES];
    
        [self.addTabViewController release];
        [navController release];
    }
    

    Problem solved.