所以我在 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 帖子,如果使用 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
委托(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/