使用UIBarButtonItem iOS9在UITabBarController中呈现popover

时间:2015-11-18 12:28:10

标签: objective-c uitableview uitabbarcontroller ios9 uibarbuttonitem

我想在iOS9中使用objectiveC在UITabBarController中呈现来自UIBarButtonItem的popover。这个popover是一个UITableViewController。我已按以下方式对其进行编码

- (IBAction)MenuButtonPopOverTouch:(id)sender {
LogoutTableViewController* content = [[LogoutTableViewController alloc] init];
content.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:content animated:YES completion:nil];
UIPopoverPresentationController *PopOverPresentation = [content popoverPresentationController];
PopOverPresentation.permittedArrowDirections = UIPopoverArrowDirectionDown;
}

我想我错过了popover的内容大小但不知道如何初始化它。任何帮助表示赞赏。如果需要,请附上我的故事板预览,请告诉我

storyboardImage

1 个答案:

答案 0 :(得分:0)

我发现这里的答案是解决方案

- (IBAction)MenuPopOver:(id)sender {

 [self performSegueWithIdentifier:@"CustomerMenu"    sender:self.MenuBarButtonItem];
 }

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
NSString *popoverIdentifier = segue.identifier;
if([popoverIdentifier isEqualToString:@"CustomerMenu"]){
    UIViewController *dvc = segue.destinationViewController;
    dvc.preferredContentSize = CGSizeMake(150, 50);
    UIPopoverPresentationController *ppc = dvc.popoverPresentationController;
    if (ppc) {
        ppc.delegate = self;    
    }
}
}

-(UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller{
return UIModalPresentationNone;
}

我通过此链接PopoverPresentationController

找到了它

它已经过测试