为什么点击按钮时显示错误?
问题描述:
对未呈现的视图进行快照会产生空的快照。当我使用UIActionsheet单击ios按钮时,确保您的视图在屏幕更新后的快照或快照之前至少呈现一次?为什么?为什么点击按钮时显示错误?
- (IBAction)btnAboutUsActions:(UIButton *)sender
{
UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle: nil
delegate:self
cancelButtonTitle: nil
destructiveButtonTitle: nil
otherButtonTitles: @"Achievment",
@"Brown Story", nil];
actionSheet.tag = 100;
[actionSheet showFromRect: sender.frame inView: sender.superview animated: YES];
}
答
使用alertController
UIAlertController *alert = [UIAlertController alertControllerWithTitle:confirmText message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *achievment = [UIAlertAction actionWithTitle:@"Achievment"
style:UIAlertActionStyleDefault
handler:nil];
[alert addAction: achievment];
[self presentViewController:alert animated:YES completion:nil];
[alert.view layoutIfNeeded]
感谢您的建议。但是,我想使用ActionSheet呢?因为我必须在点击按钮时执行多个选项并且多个选项视图显示在按钮下方。 –
尝试在显示它之后写入[[actionSheet.view layoutIfNeeded]]。 – pkc456
我已经试过了! [actionSheet layoutIfNeeded];它不工作! –