【问题标题】:Why error is showing on click of button?为什么单击按钮时显示错误?
【发布时间】:2016-09-19 18:12:26
【问题描述】:

对尚未渲染的视图进行快照会导致快照为空。当我在 ios 中单击按钮时使用 UIActionsheet 时,确保您的视图在快照或屏幕更新后的快照之前至少渲染一次?为什么?

- (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];

}

【问题讨论】:

    标签: objective-c


    【解决方案1】:

    使用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]
    • 我已经试过了! [actionSheet 布局如果需要];它不工作!
    • 实际上我正在尝试通过单击 UIActionsheet 按钮在 Web 视图中打开链接!!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-07-28
    • 2022-10-31
    • 1970-01-01
    • 1970-01-01
    • 2021-08-18
    • 2014-12-04
    • 2021-10-20
    相关资源
    最近更新 更多