My scenario is like this. I have a tableview cell which has a button.If fire it menu will popout like below
for the above menu popover the source is the button that is appearning extreme right of each cell.
I have another table view called diplayAccounts. on click of the popover menu's cell (i.e. view hierarchy) the displayAccounts View controller needs to be displayed as a popover. My doubt is that what should be the source for it.
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
menuTapped(self)
}
the method menuTapped is as follows
func menuButtonTapped(sender: AnyObject)
{
let storyboard : UIStoryboard = UIStoryboard(name: "Storyboard", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("HierarchyTableViewController") as! HierarchyTableViewController
vc.modalPresentationStyle = UIModalPresentationStyle.Popover
let popover: UIPopoverPresentationController = vc.popoverPresentationController!
popover.sourceView = sender as? UIView
popover.delegate = self
presentViewController(vc, animated: true, completion:nil)
}
And the error that I'm getting
Its not good idea to present pop over inside another popover(From Apple Mobile Human Interface Guidelines)
The best thing you can do is like
In pop over view controller class
In cell class that displays the button from which popover is presented
(i.e. the cell displaying 44087 and 111 in the picture above)
Show the other pop over you wanted.
UPDATE
This will be the popover view controller that displays list of items as you shown above
PopOverWithListItemsViewController.h file
#import <UIKit/UIKit.h>
@protocol PopoverWithListItemsViewDelegate <NSObject>
- (void)didSelectedListItemAtIndex:(NSInteger)index;
@end
@interface PopOverWithListItemsViewController : UIViewController
@property (nonatomic, weak) id<PopoverWithListItemsViewDelegate> delegate;
@end
In table view selection event, add the delegate call like
NSInteger indexOfSelectedItem = 4;// jus for demo setting index as 4
[self.delegate didSelectedListItemAtIndex:indexOfSelectedItem];
And in the class from which you presenting list popover, add the following
Step1
The class from which you present the pop over should confirm to the delegate like follows
@interface ViewController () <PopoverWithListItemsViewDelegate> // let ViewController is the class from which you presenting the pop over
Step2
// Let this be the cell's button tap event from which you presenting the pop over
- (IBAction)buttonTapEvent:(id)sender
{
// Presenting pop over sections
PopOverWithListItemsViewController *listItemsPopOverVC = [[PopOverWithListItemsViewController alloc] init];
listItemsPopOverVC.delegate = self;
// pop over presenting with listItemsPopOverVC as popover's view controller
}
Step3
// Delegate method implementation.
- (void)didSelectedListItemAtIndex:(NSInteger)index
{
// Here we get the index of the selected cell in the popover.
// Present the new popover from here, after customizing the new pop over contents.
}