Abhinav
Abhinav

Reputation: 38162

'Done' button not visible in the Modal view

I am trying to present a modal view from one of my view. The presenter view is already shown as a modal from a custom view. My problem is that I am not able to see the 'Done' button on the new Modal view presented. Below is my code. Am I missing something?

    UIViewController *aViewController = [[UIViewController alloc] init];
    UINavigationController *aNavigationController = [[[UINavigationController alloc] initWithRootViewController:aViewController] autorelease];
    [aNavigationController.navigationBar setBarStyle:UIBarStyleBlack];
    UIBarButtonItem *aBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(dismissMe)];
    [aNavigationController.navigationItem  setLeftBarButtonItem:aBarButtonItem];
    MyView *aView = [[MyView alloc] initWithFrame:self.view.frame];
    [aViewController.view addSubview:aView];
    [self presentModalViewController:aNavigationController animated:YES];
    [aViewController release];

- (void)dismissMe {
    [self dismissModalViewControllerAnimated:YES];
}

enter image description here

Upvotes: 1

Views: 1982

Answers (1)

matteodv
matteodv

Reputation: 3982

If I understand weel the question, you can try a solution like this:
Write this in the viewDidLoad or init method of the modal view controller you want to show from the actual view:

UIBarButtonItem *done = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self selector:@selector(dismissMe)];
self.navigationController.leftBarButtonItem = done;

and implement you dismissMe method.
Instead, in the presenter controller write this where you want to present the new modal controller:

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controllerYouWantToShow];
[self presentModalViewController:navController animated:YES];

Obviusly, controllerYouWantToShow is a pointer/variable pointing your view controller you want to show... I usually do this to solve a problem like yours... However, check the code because I havent't tested it :)
Hope it helps!

Upvotes: 3

Related Questions