Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Navigation Controller in popover

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.

like image 986
user640918 Avatar asked Mar 02 '11 10:03

user640918


People also ask

What can I display in the popoverpage?

The PopoverPage will display inside of the popover, and can be anything. Below is an example of a page with items that close the popover on click.

How to open a popover on the click of a button?

To open a popover on the click of a button, pass $event to the method which creates and presents the popover: The PopoverPage will display inside of the popover, and can be anything. Below is an example of a page with items that close the popover on click.

How do I change the adaptation behavior of a popover?

You can do that by adding a button, embedding the popover in a dismissible container view controller, or changing the adaptation behavior itself. For tips on how to configure a popover presentation, see Presenting a View Controller in a Popover.

How do I add context to a popover?

A common flow is the following: Present a small popover to add more context to something the user tapped. When the user taps on a button in that popover, push on a new view controller with more information. UIKit provides the building blocks for this out of the box, but the kicker is when the two view controllers are different sizes.


3 Answers

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!

like image 68
Hamed Rajabi Avatar answered Sep 25 '22 21:09

Hamed Rajabi


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 :)

like image 32
jdmunro Avatar answered Sep 26 '22 21:09

jdmunro


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)];
 }
like image 21
MouzmiSadiq Avatar answered Sep 25 '22 21:09

MouzmiSadiq