ios - UIActionSheet - 快照尚未呈现的 View 会导致空快照

标签 ios objective-c uitableview uisplitviewcontroller uiactionsheet

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

Snapshotting a view that has not been rendered results in an empty snapshot. Ensure your view has been rendered at least once before snapshotting or snapshot after screen updates.

我搜索了很多关于这个问题的 SO 帖子,如果使用 UIImagePickerControllerUIAlertViewController,它们似乎都解决了这个问题 - 但似乎没有一个得到/解决使用 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 委托(delegate)方法来解决其他一些问题,所以我想知道是否需要添加一些代码来解决委托(delegate)方法中的问题?:

- (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
{

}

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

最佳答案

我遇到了完全相同的问题,但由于似乎没有任何措施有效,所以问题更进一步。值得注意的是,UIActionSheet 已在 iOS 8 中弃用,应使用 .ActionSheet 的 preferredStyle 替换为 UIAlertController。使用 UIAlertController 时,我确实得到了相同的调试输出,但至少我的操作似乎有效。

不过,我可以通过 here 中的解决方案确认这一点,调试消息消失。

关于ios - UIActionSheet - 快照尚未呈现的 View 会导致空快照,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37436761/

相关文章:

ios - 如何在tableview cell swift 3.0中设置选中的复选标记

ios - 在 iOS( objective-c )中单击 Button 时,如何在 UITableView 中获取特定的 JSON 数据?

objective-c - TBXML 中的异步和 initWithURL

javascript - 当我在设备中运行 React Native 应用程序而不通过电缆连接到电脑时,它显示 2 个月前的应用程序状态

ios - 如何从 Swift 调用 NSOperations 子类的 Obj C 自定义 Init 方法

iphone - iPhone 上 NSString 的 AES 加密

ios - 有没有办法在 Interface Builder 中设置 UINavigationBar 的委托(delegate)?

ios - 如何滑动以删除特定部分中的行

ios - UITableview委托(delegate)方法在json方法之前调用

ios - 删除 UITableView 行 - 复制单元格