Question

I've created a bare bones Master/Detail iPad application using the supplied template. It creates two view controllers (Master and Detail). I've created a view additional view controllers that get popped on top of the master view controller (pretty much drilling down tableviews until finally hitting a cell that populates the detail view. I've added the code below to load the master view controller popover to the specified dimensions (code below also shows when a selection is selected from the master view controller tableview):

@implementation MasterViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.vehicles = [[NSArray alloc] initWithObjects:@"Cars", @"Trucks", @"Boats", nil];

        self.title = @"Vehicle Type";
        self.clearsSelectionOnViewWillAppear = NO;
        self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0);
    }
    return self;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (!self.studySessionViewController)
    {
        self.secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    }
    [self.navigationController pushViewController:self.secondViewController animated:YES];
}

When the popover is selected when the application first loads, everything looks great. However, when a user clicks back to the MasterViewController, the size of the popover is the same size as the largest view controller that was pushed on the stack. I've searched around and I've added the following code in the Master view controller class:

- (void)viewWillAppear:(BOOL)animated
{
    self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0);
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0);
    [super viewDidAppear:animated];
}

However, this has no effect. Also once the popover is closed (either by rotation or deselecting the popover on the UI), the popover size of the largest table view controller that was previously pushed on the stack is still retained and completely ignores the above dimensions. What am I missing?

Was it helpful?

Solution

I couldn't understand your whole problem but I think that the base of your problem is bad size of a Popover.

Usually, the problems with Popover size come of the fact that [UIViewController contentSizeForViewInPopover] can be set only before you create the UIPopoverController instance. It's just the default value for the popover size.

When you create the UIPopoverController instance with your controller as its contents, the contentSizeForViewInPopover is copied into [UIPopoverController popoverContentSize] and never read again. If you change it on the contents, Popover size is not updated.

The only way how you can change size of an already created UIPopoverController instance is using the property [UIPopoverController popoverContentSize] or method [UIPopoverController setPopoverContentSize:animated:].

OTHER TIPS

You are trying to set the popover size in the MasterViewController itself. Here lies the issue. For self.contentSizeForViewInPopover = CGSizeMake(320.0, [vehicles count] * 52.0); to work you will have to use this in the DetailViewController instead, since the DetailViewController is the one that has a popover. Basic idea here is that you set the size in parent view controller and not the controller itself.

your going to have to setup the frames.

incomingCallViewController = [[IncomingCallViewController alloc]initWithNibName:@"IncomingCallViewController" bundle:nil];
            [incomingCallViewController.view setFrame:CGRectMake(400, 200, 377, 243)];

            [self.navigationController pushViewController:incomingCallViewController.view]; 

this of course is sample code from one of my projects, replace incomingCallViewController with your own class and declare it in the header

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top