Ios 如何在XIB/情节提要中使用通用UITableViewCell? 协议可配置{ } 类配置:可配置{ } 类GenericTableViewCell:UITableViewCell{ } 类CoolTableViewCell:GenericTableViewCell{ 初始化(编解码器:NSCoder){ /*init()方法在下面不起作用…因此无法重写 初始化是正确的。看起来这应该可以工作——GenericTableViewCell是 _仍然是UITableViewCell的子类,那又怎么样? */ super.init(aDecoder) /*此外,如果查看CoolTableViewCell.xib,您将发现没有办法 在类下拉列表中设置这个类。所以,我不能手动设置视图 在init中加载一个nib,我不能将这个类设置为 用在笔尖上。 */ } }

Ios 如何在XIB/情节提要中使用通用UITableViewCell? 协议可配置{ } 类配置:可配置{ } 类GenericTableViewCell:UITableViewCell{ } 类CoolTableViewCell:GenericTableViewCell{ 初始化(编解码器:NSCoder){ /*init()方法在下面不起作用…因此无法重写 初始化是正确的。看起来这应该可以工作——GenericTableViewCell是 _仍然是UITableViewCell的子类,那又怎么样? */ super.init(aDecoder) /*此外,如果查看CoolTableViewCell.xib,您将发现没有办法 在类下拉列表中设置这个类。所以,我不能手动设置视图 在init中加载一个nib,我不能将这个类设置为 用在笔尖上。 */ } },ios,swift,uitableview,generics,Ios,Swift,Uitableview,Generics,上面代码中的注释解释了这个问题。有趣的是,在xib中,我可以将GenericTableViewCell视为类下拉列表中的一个选项,它甚至不应该工作,因为generict:Configurable不会被设置 答案可能是“不适用于objective-c类”,但希望我错了。有什么想法吗 protocol Configurable { } class CoolConfiguration : Configurable { } class GenericTableViewCell<T: Confi

上面代码中的注释解释了这个问题。有趣的是,在xib中,我可以将
GenericTableViewCell
视为类下拉列表中的一个选项,它甚至不应该工作,因为generic
t:Configurable
不会被设置

答案可能是“不适用于objective-c类”,但希望我错了。有什么想法吗

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. 
        */
    }
}