[英]How to access IBOutlet in UITableViewController Class if the IBOutlet is in UIViewController Class
[英]Use UIViewController class on UITableViewController
我有一個從UIViewController繼承的Swift類,我想知道是否有什么方法可以在UITableViewController上使用同一類以避免重復。
class GradientViewController: UIViewController {
// My class
}
有沒有辦法像這樣在UITableViewController上使用此類?
class MyTableViewController: GradientViewController {
// My table view controller
}
提前致謝
Swift僅支持單一繼承。
您可以使用協議來避免重復。
protocol YourProtocolName {
// Protocol stuff
}
class GradientViewController: UIViewController, YourProtocolName {
// Implement protocol requirements
}
class MyTableViewController: UITableViewController, YourProtocolName {
// Implement protocol requirements
}
如果有道理,您甚至可以使用協議擴展來提供默認的實現,從而使符合類型不需要添加任何代碼即可符合。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.