子类化UIAlertController [英] Subclassing UIAlertController

查看:100
本文介绍了子类化UIAlertController的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iOS 8之前的版本中,我们必须使用UIAlertViewUIActionSheet

With pre-iOS 8 we had to use the UIAlertView and UIActionSheet

不允许我们弄乱它们的视图层次结构或子类.

Which we weren't allowed to mess with the view hierarchy or subclass on either them.

UIAlertView文档

UIAlertView类旨在按原样使用,并且不支持子类化.此类的视图层次结构是私有的,不能修改.

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

UIActionSheet文档

UIActionSheet并非旨在被子类化,也不应将视图添加到其层次结构中.如果您需要提供比UIActionSheet API提供的自定义表更多的自定义表,则可以创建自己的表并使用presentViewController:animated:completion:模态地呈现它.

UIActionSheet is not designed to be subclassed, nor should you add views to its hierarchy. If you need to present a sheet with more customization than provided by the UIActionSheet API, you can create your own and present it modally with presentViewController:animated:completion:.

但是,在iOS 8上,Apple引入了UIAlertController来代替UIAlertViewUIActionSheet(请查看预发布文档

However with iOS8 Apple have introduced UIAlertController to replace both UIAlertView and UIActionSheet (Check the pre-release documentation here).

因此在此预发布文档中,没有关于不能继承或更改视图层次结构的内容,它甚至具有此方法addTextFieldWithConfigurationHandler:,因此我们将能够更改视图层次结构和/或子类UIAlertController不用担心苹果会批准还是拒绝我们的申请?

So in this pre-release documentation there is nothing about not being able to subclass or change the view heirarchy, it even has this method addTextFieldWithConfigurationHandler: so will we be able to change the view heirarchy and/or subclass UIAlertController without worrying whether Apple will approve or reject our applications?

推荐答案

此答案已过时.请参阅 limon的答案.

ViewController != View.苹果公司不更改UIAlertView外观的策略不会影响当前的视图控制器.我没有理由不解释为什么您不能对UIAlertController进行子类化.但是使用它可能会使用自定义增长的东西替换警报视图变得更加困难,因为警报视图现在仅由超出您控制范围的类间接创建.对于UIAlertView

ViewController != View. Apple's policy of not changing the appearance of an UIAlertView does not affect the presenting view controller. I see no reason why you shouldn't be able to subclass the UIAlertController. But using it may be making it harder to replace the alert view with something custom grown, as the alert view is now only created indirectly by classes out of your control. And for UIAlertView same rules applies as before.

这篇关于子类化UIAlertController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆