【发布时间】:2015-06-04 01:43:32
【问题描述】:
我想继承声明如下的 UITableViewRowAction 类:
class UITableViewRowAction : NSObject, NSCopying {
convenience init(style: UITableViewRowActionStyle, title: String!, handler: (UITableViewRowAction!, NSIndexPath!) -> Void)
var style: UITableViewRowActionStyle { get }
var title: String!
@NSCopying var backgroundColor: UIColor! // default background color is dependent on style
@NSCopying var backgroundEffect: UIVisualEffect?
}
我希望我的子类覆盖这里存在的便利 init 并调用 super 来获得便利 init。
这是我想做的:
public class MySubclass : UITableViewRowAction {
let handler : (UITableViewRowAction!, NSIndexPath!) -> Void
public init(style: UITableViewRowActionStyle, title: String!, handler: (UITableViewRowAction!, NSIndexPath!) -> Void) {
self.handler = handler
super.init(style: style, title: title, handler: handler) // error == Must call a designated initializer of the superclass 'UITableViewRowAction'
}
}
我想这样做是为了将处理程序公开为只读属性,以便能够对处理程序执行我认为应该执行的操作进行单元测试。
所以我的问题是超类没有公开传递给 init 方法的处理程序,也没有办法在 init 方法之外设置它。
【问题讨论】: