子类化UIAlertController [英] Subclassing UIAlertController
问题描述
在iOS 8之前的版本中,我们必须使用UIAlertView
和UIActionSheet
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类旨在按原样使用,并且不支持子类化.此类的视图层次结构是私有的,不能修改.
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 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
来代替UIAlertView
和UIActionSheet
(请查看预发布文档
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屋!