如何在XIB / Storyboard中使用通用UITableViewCell?

时间:2015-10-14 19:45:59

标签: ios swift uitableview generics

protocol Configurable {
}

class CoolConfiguration : Configurable {
}

class GenericTableViewCell<T: Configurable>: UITableViewCell  {
}

class CoolTableViewCell : GenericTableViewCell<CoolConfiguration> {
    init(aDecoder: NSCoder) {
        /*  The init() method doesn't work below...so no way to override
            the init properly. Seems like this should work -- GenericTableViewCell is
            _still_ a subclass of UITableViewCell, so what the heck?
        */
        super.init(aDecoder)

        /*  Additionally if you look in CoolTableViewCell.xib, you'll see there is no way 
            to set this class in the class dropdown. So, I can't set the view manually by 
            loading a nib here in the init and I can't set this class as the class to be 
            used in the nib. 
        */
    }
}

上面代码中的注释解释了该问题。有趣的是,在xib中我可以看到GenericTableViewCell作为类下拉列表中的一个选项,由于通用T: Configurable无法设置,因此该功能无法正常工作。

可能答案是&#34;不适用于Objective-c类,&#34;但希望我错了。有任何想法吗?

0 个答案:

没有答案