凌云志轩 2016-05-27 03:46 采纳率: 0%
浏览 1434
已采纳

swift alertcontroller添加view出错

这段代码出错了,添加alertVC.setValue(alertView, forKey: "FullintentViewController")的时候就会出现terminating with uncaught exception of type NSException的错误,是怎么回事呢
图片说明

  • 写回答

2条回答 默认 最新

  • oyljerry 2016-05-27 06:37
    关注

    直接addSubview

     var alertController = UIAlertController(title: "\n\n\n\n\n\n", message: nil, preferredStyle: UIAlertControllerStyle.ActionSheet)
    
    let margin:CGFloat = 8.0
    let rect = CGRectMake(margin, margin, alertController.view.bounds.size.width - margin * 4.0, 100.0)
    var customView = UIView(frame: rect)
    
    customView.backgroundColor = UIColor.greenColor()
    alertController.view.addSubview(customView)
    
    let somethingAction = UIAlertAction(title: "Something", style: UIAlertActionStyle.Default, handler: {(alert: UIAlertAction!) in println("something")})
    
    let cancelAction = UIAlertAction(title: "Cancel", style: UIAlertActionStyle.Cancel, handler: {(alert: UIAlertAction!) in println("cancel")})
    
    alertController.addAction(somethingAction)
    alertController.addAction(cancelAction)
    
    self.presentViewController(alertController, animated: true, completion:{})
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?