【问题标题】:Launch a UIPopover on click of a button inside UIActionSheet单击 UIActionSheet 中的按钮启动 UIPopover
【发布时间】:2015-08-27 05:16:33
【问题描述】:

在我的表格视图中向左滑动一行时,我有两个 UITableViewRowAction 按钮(删除和更多)。点击 More 按钮后,我将展示一个 UIActionSheet,其中包含两个名为 Edit NickNameEdit Photo 的按钮,如下所示:

现在我正在尝试通过单击编辑昵称来启动 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 中都能很好地工作,但在这种情况下它没有显示任何弹出框。

上面的代码行在运行时被执行,但是什么都没有发生。

谁能告诉我是否可以做这样的事情,或者我在这里做错了什么。如果不可能,请向我建议一种替代方法,以替代如何在单击 Edit NickName 按钮时启动弹出窗口之类的内容。

提前致谢!

【问题讨论】:

  • 您不应该通过0 获得允许的方向,并且您当然不应该通过零大小的矩形来呈现。为什么不传递单元格的矩形和视图?
  • @rmaddy 我正在传递0 以获得允许的方向,因为我不想要任何相关的方向。而且我尝试过更改矩形的大小,但仍然无法正常工作。无论如何,相同的代码在 UI 中的普通按钮的操作中工作。
  • 可能问题在于20,20 原点位于导航栏下方。
  • 尝试了所有矩形参数的组合。但是,它不起作用。我猜问题出在 UIActionsheet 按钮上。
  • 不要使用clickedButtonAtIndex 委托,而是尝试使用didDismissWithButtonIndex: 委托方法。问题可能是在关闭操作表之前尝试显示弹出框。

标签: ios objective-c uipopovercontroller uiactionsheet


【解决方案1】:

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

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

【讨论】:

  • OP 已经在使用主队列。操作表委托方法总是在主队列中调用。
猜你喜欢
  • 2011-01-11
  • 1970-01-01
  • 1970-01-01
  • 2015-12-13
  • 2011-02-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多