单击UIActionSheet内的按钮启动UIPopover

时间:2015-08-27 05:16:33

标签: ios objective-c uipopovercontroller uiactionsheet

在Table视图的左侧滑动中,我有两个UITableViewRowAction按钮(Delete和More)。单击更多按钮,我将展示一个UIActionSheet,其中包含两个名为编辑NickName 的按钮和编辑照片,如下所示:

lookaround

现在我尝试点击Edit NickName启动UIPopover。为此,我使用以下代码:

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
NSString *buttonTitle = [actionSheet buttonTitleAtIndex:buttonIndex];    

    if ([buttonTitle isEqualToString:@"Edit NickName"]) {
        NSLog(@"Edit NickName");
        UIStoryboard *secondStoryBoard = [UIStoryboard storyboardWithName:@"SplitView" bundle:nil];
        EditNickNameViewController *popVC = [secondStoryBoard instantiateViewControllerWithIdentifier:@"EditNickNameViewController"];

        popover = [[UIPopoverController alloc] initWithContentViewController:popVC];
        popover.delegate=self;
        popover.popoverContentSize = CGSizeMake(600, 300);
        [popover presentPopoverFromRect:CGRectMake(20,20, 0, 0) inView:self.view
           permittedArrowDirections:0 animated:YES];



    }
    if ([buttonTitle isEqualToString:@"Edit Image"]) {
        NSLog(@"Edit Image");
    }
}

上面的代码在任何普通UIButton的IBAction中运行良好,但在这种情况下它没有显示任何弹出窗口。

上面的代码行正在运行时执行,但什么也没发生。

任何人都可以告诉我是否可以做这样的事情,或者我在这里做错了。如果无法做到,请点击编辑NickName 按钮,向我建议如何启动类似pop的内容。

提前致谢!

1 个答案:

答案 0 :(得分:0)

在主队列中显示您的弹出窗口;

dispatch_async(dispatch_get_main_queue(), ^{
       [popover presentPopoverFromRect:CGRectMake(20,20, 0, 0) inView:self.view
           permittedArrowDirections:0 animated:YES];
    });