Creating button for popover view anchor at run time?

I'm gonna try making a dummy view that's the size and shape of the views I want to present the popover from, wire that to the segue popover target, and then move the view to the right position in prepareForSegue:sender.

Up vote 10 down vote favorite share g+ share fb share tw.

This may not be possible, but I'm hoping someone will have an idea how to do it. I have an app I'm porting from iPhone only to Universal. On the iPhone, I'm using a Tabbed application.

I use three tabs for the normal data to be displayed. I have a forth tab that's only displayed if certain conditions are met. To add the tab, I do: if (UIDevice currentDevice userInterfaceIdiom == UIUserInterfaceIdiomPhone) { UITabBarController *tabController = (UITabBarController *) self.

RootViewController; NSMutableArray* newArray = NSMutableArray arrayWithArray: tabController. ViewControllers; newArray addObject: theStoryboard instantiateViewControllerWithIdentifier: @"AdditionalView-Phone"; tabController setViewControllers:newArray animated:YES; } For the iPad, I have enough space on the initial view to display everything from the main three tabs in the iPhone UI. So all I need is one additional (small) view for the "Additional" data.

I wanted to do it using a popOver view, so I set up the initial view with a Nav bar and popover button as in the Utility App template. But now I'm stuck. I can't figure out how to create that popover button at run time and make it do the segue to the popOver view properly.

I can add the button like this: UIBarButtonItem *flipButton = UIBarButtonItem alloc initWithTitle: @"Modem" style: UIBarButtonItemStylePlain target: self action: @selector(togglePopover:); self.navBar.topItem. RightBarButtonItem = flipButton; but I get an exception: 'NSInternalInconsistencyException', reason: 'UIStoryboardPopoverSegue must be presented from a bar button item or a view. ' I'm pretty sure this is because I don't have an anchor set for the popOver segue.

The button doesn't exist in the storyboard, so I can't set it there. And I can't seem to find an API to set it at run time. I also tried creating the button in IB, but not in the view hierarchy, and then just setting the rightBarButtonItem property to my existing button.

That also works, but I still can't set that button as the anchor for the popover view. I can set the Navigation Bar as the anchor, but that makes it anchor to the title in the nav bar, which looks silly. Any ideas?

Ios ipad uinavigationbar uipopovercontroller link|improve this question edited Oct 16 '11 at 21:05 asked Oct 16 '11 at 20:33Flyingdiver925310 89% accept rate.

– Rog Dec 28 '11 at 3:57 Yep, make a hidden UIView from which to present the popover and move that where ever you need. – Michael Forrest Mar 21 at 11:57.

It works! Having the dummy view hidden doesn't seem to cause problems either. – Michael Forrest Jan 16 at 16:50.

I was curious about this too so I made a quick test project. You're right, there doesn't seem to be a way to configure the popover segue at runtime or add an anchor point to a button that's not in the view hierarchy using Interface Builder. My solution was to set everything up in IB with the UIBarButtonItem visible and connected to an IBOutlet property, then remove it from the navigation bar in -viewDidLoad: - (void)viewDidLoad { super viewDidLoad; self.navigationItem.

RightBarButtonItem = nil; } Then I simply add it back or remove it by tapping another button: - (IBAction)toggleBarButtonItem:(id)sender { UIBarButtonItem *item = (self.navigationItem. RightBarButtonItem == nil)? Self.

PopoverBarButtonItem : nil; self. NavigationItem setRightBarButtonItem:item animated:YES; } You could conditionally keep or remove the button in -viewDidLoad the same way. The segue remains anchored to the UIBarButtonItem.

I'm not sure this is exactly what you want, but this is what I would do. Create a button and set it up with some target/action. Call that target/action method presentPopover:(UIButton *)sender; Then in the presentPopover method, say UIViewController *customAdditionalViewController = MySpecialVC alloc init; //Configure the customAdditionalViewController //Present the customAdditionalViewController in a Popover UIPopoverController *popover = UIPopoverController alloc initWithViewController:customAdditionalViewController; //Set popover configurations popover presentPopoverFromRect:sender.

Frame inView:self. View permittedArrowDirections:/*whatever you want*/ animated:YES; That is how I would handle your use case.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions