【问题标题】:UIActionSheet - Snapshotting a view that has not been rendered results in an empty snapshotUIActionSheet - 对尚未渲染的视图进行快照会导致快照为空
【发布时间】:2016-05-25 12:12:40
【问题描述】:

所以我在splitViewController 中有一个UITableView。我在UITableViewCell 中有一个UIActionSheet,如果单元格包含电话号码,actionSheet 会显示选项列表(发送消息、添加到联系人、复制)。当 iPad 处于纵向时,这一切都很好,但是当在横向中点击单元格时,我收到以下错误:

对尚未渲染的视图进行快照会导致快照为空。确保您的视图在快照之前或屏幕更新后的快照之前至少渲染过一次。

我已经搜索了很多关于这个问题的 SO 帖子,如果使用 UIImagePickerController 或 UIAlertViewController,它们似乎都解决了这个问题 - 但使用 UIActionSheet 时似乎没有一个得到/解决错误。

这是我的代码:

            UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil
                                                                 delegate:self
                                                        cancelButtonTitle:nil
                                                   destructiveButtonTitle:nil
                                                        otherButtonTitles:@"Send Message", @"Add to Contacts", @"Copy", nil];


        CGRect cellRect = cell.bounds;
        cellRect.size.width = cell.frame.size.width * 2;
        cellRect.origin.x = -(cell.frame.size.width / 2);

        [actionSheet showFromRect:cellRect inView:cell animated:YES];

我还实现了UIActionSheet委托方法来解决一些其他问题,所以我想知道是否需要添加一些代码来解决委托方法中的问题?:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
    [self.tableView deselectRowAtIndexPath:indexPath animated:YES];
}

- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    dispatch_async(dispatch_get_main_queue(), ^{
        [actionSheet dismissWithClickedButtonIndex:buttonIndex animated:YES];
    });

}

- (void)didPresentActionSheet:(UIActionSheet *)actionSheet
{

}

非常感谢任何帮助。这个警告可能并不严重,但我不确定苹果是否会因为这个警告而拒绝它。该应用程序不会崩溃或其他任何事情,但我仍然想摆脱错误。谢谢。

【问题讨论】:

  • 延迟演示直到下一个运行循环的原因是什么?
  • 我认为之前使用UIPopoverController 尝试此功能时遗留下来的代码。我现在将其删除,好地方。
  • 我认为问题出在这一行:[actionSheet showFromRect:cellRect inView:cell animated:YES]。您正在单元格中展示 actionSheet,而您想要做的是在 viewController 的根视图中展示它。尝试将cell 更改为self.view
  • 不幸的是,这并没有帮助 - 它只是在tableView 的第一个单元格下方显示actionSheet。我也尝试将其更改为cell.contentView,但仍然是相同的警告消息。我很难过,因为它似乎只在我使用任何相机功能时才会出现。

标签: ios objective-c uitableview uisplitviewcontroller uiactionsheet


【解决方案1】:

我遇到了完全相同的问题,但它甚至更进一步,因为似乎没有任何操作有效。值得注意的是,UIActionSheet 在 iOS 8 中已被弃用,应使用 .ActionSheet 的首选样式将其替换为 UIAlertController。使用 UIAlertController 时,我确实得到了相同的调试输出,但至少我的操作似乎有效。

不过,我可以确认,使用 here 的解决方案,调试消息消失了。

【讨论】:

    猜你喜欢
    • 2017-02-23
    • 1970-01-01
    • 2016-12-08
    • 1970-01-01
    • 2013-09-24
    • 1970-01-01
    • 2020-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多