Navigation Controller in popover

14,405

Solution 1

I did it before and it works well! Just assign this function to your button (perhaps an UIBarButtonItem):

UIPopoverController *popover;
bool isPopoverOpen = false;
-(void)openPopover{
    if(!isPopoverOpen){
        FirstViewController *firstViewCtrl = [[PartsViewCtrl alloc] init];
        UINavigationController *navbar = [[UINavigationController alloc] initWithRootViewController:firstViewCtrl];
        [firstViewCtrl release];
        navbar.contentSizeForViewInPopover = CGSizeMake(TABLE_WIDTH, TABLE_HEIGHT);
        popover = [[UIPopoverController alloc] initWithContentViewController:navbar];
        [navbar release];
        popover.delegate = self;
        popover.popoverContentSize = CGSizeMake(TABLE_WIDTH, TABLE_HEIGHT);
        [popoverOnPartsView presentPopoverFromBarButtonItem:barButtonItem permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
        isPopoverOpen = true;
    }else{
        [popover dismissPopoverAnimated:YES];
        [popover release];
        isPopoverOpen = false;
    }
}

And implement this function to FirstViewController which has an UITableView:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    SecondViewController *secondViewController = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:secondViewController animated:YES];
    [secondViewController release];
}

Now you can add an UITableView to SecondViewController, Too. And use this scenario for other tables!

I hope it works for you!

Solution 2

When you create the popover, you just need to allocate a UINavigationController and use this to manage the view hierarchy within the popover itself. A quick web search revealed this tutorial which covers the things you need to know.

I also meant to add that you should get up to speed with Objective-C and iOS development in general. Don't try and blindly use things you've found on the net without understanding what you're actually doing :)

Solution 3

Do the following steps 

1)In the action of button (by clicking on that button pop over should appear) write the code

[here PopOverContentViewController is a viewController where i have table view and several list of items which should be displayed when the pop over arrives]

 - (IBAction)callPopOver:(id)sender 
  {


    UIButton *button = (UIButton*)sender;
    PopOverContentViewController1 *popOverContent = [[PopOverContentViewController1     alloc]initWithNibName:@"PopOverContentViewController1" bundle:nil];

    UINavigationController *navbar = [[UINavigationController alloc]  initWithRootViewController:popOverContent];

    navbar.contentSizeForViewInPopover = CGSizeMake(266, 200);
    popover = [[UIPopoverController alloc] initWithContentViewController:navbar];
    popover.delegate = self;
    [popover presentPopoverFromRect:CGRectMake(button.frame.size.width / 2,   button.frame.size.height / 1, 1, 1) inView:button   permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
    [popover setPopoverContentSize:CGSizeMake(266, 200) animated:YES]; 
    [popUpContent release];


    }      

2)now to change the table view on clicking on any of the rows type this code in PopOverViewController.m

[here PopOverViewController2 is the ViewController where we have the next table view to be displayed]

    -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    PopOverViewController2 *secondViewController = [[PopOverViewController2 alloc] init];
    [self.navigationController pushViewController:secondViewController animated:YES];
    [secondViewController release];
    }

3)to avoid the change in size of popover while navigation write the following code in viewDidLoad of both view controllers (ie PopOverContentViewController1 and PopOverContentViewController2)

 - (void)viewDidLoad
 {
  [super viewDidLoad];
  [self setContentSizeForViewInPopover:CGSizeMake(266, 200)];
 }
Share:
14,405
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin about 2 years

    I am a total newbie in the ipad app development.

    I am interested in creating an application where i have a popover showing a tableview with list of items. Then i select an item and the view drills to another tableview consisting of another list of items and a navigate back button as well.

    the level to which i would be drilling down is dynamic.

    Please guide me with appropriate resources to help me solve the problem.