Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/114.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 创建自己的UITableViewController_Ios_Swift_Uitableview - Fatal编程技术网

Ios 创建自己的UITableViewController

Ios 创建自己的UITableViewController,ios,swift,uitableview,Ios,Swift,Uitableview,我想基于我的配置创建我自己的UITableViewController class ProtectedViewController: UIViewController { //... } Swift不支持多重继承,因此我复制了源UITableViewController,并将UIViewController更改为我的ProtectedViewController类: @available(iOS 2.0, *) class ProtectedUITableViewController

我想基于我的配置创建我自己的UITableViewController

class ProtectedViewController: UIViewController {
    //...
}
Swift不支持多重继承,因此我复制了源
UITableViewController
,并将
UIViewController
更改为我的
ProtectedViewController
类:

@available(iOS 2.0, *)
class ProtectedUITableViewController : ProtectedViewController, UITableViewDelegate, UITableViewDataSource {

    public init(style: UITableViewStyle)
    public init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: NSBundle?)
    public init?(coder aDecoder: NSCoder)

    public var tableView: UITableView!
    @available(iOS 3.2, *)
    public var clearsSelectionOnViewWillAppear: Bool // defaults to YES. If YES, any selection is cleared in viewWillAppear:

    @available(iOS 6.0, *)
    public var refreshControl: UIRefreshControl?
}
但是有很多错误:


由于您尚未实现这些方法,因此代码无法编译。这看起来像是Objective-C中的.h文件(只是方法签名)

您应该为所有init添加实现。例如。:

初始化(样式:UITableViewStyle){
//在这个init中做一些事情
}

由于您尚未实现这些方法,因此代码无法编译。这看起来像是Objective-C中的.h文件(只是方法签名)

您应该为所有init添加实现。例如。:

初始化(样式:UITableViewStyle){
//在这个init中做一些事情
}

根据您的ViewController创建“TableviewController”试图实现什么?如果您想添加更多的方法或帮助器方法,请创建UITableViewController的子类。但如果我创建UITableViewController的子类,则应复制ProtectedViewController中的所有方法。。。因此将有大量类似的代码,而这不是子类化的工作方式。。。从什么时候开始,当你创建子类时,你必须复制所有的东西?@luk2302我想创建这样的东西:类MyTableViewController:UITableViewController,ProtectedViewController{}。你想做的是根本不可能的。即使复制了所有方法,也不会有
UITableViewController
。根据ViewController创建“TableviewController”试图实现什么?如果您想添加更多的方法或帮助器方法,请创建UITableViewController的子类。但如果我创建UITableViewController的子类,则应复制ProtectedViewController中的所有方法。。。因此将有大量类似的代码,而这不是子类化的工作方式。。。从什么时候开始,当你创建子类时,你必须复制所有的东西?@luk2302我想创建这样的东西:类MyTableViewController:UITableViewController,ProtectedViewController{}。你想做的是根本不可能的。即使复制所有方法,您仍然不会有
UITableViewController
。是否有更好的解决方案不从UIViewController而是从我的ProtectedViewController继承表视图(您想修改UITableViewController或UITableView的行为吗?就我个人而言,我从不使用UITableViewController,而是使用普通的UiViewController,创建我自己的UITableView,并设置数据源和委托手册。这更灵活,使您能够创建自己的实现UITableViewDataSource的类是否有更好的解决方案不从UIViewController而是从我的ProtectedViewController继承表视图(您想修改UITableViewController或UITableView的行为吗?就我个人而言,我从不使用UITableViewController,而是使用普通的UiViewController,创建我自己的UITableView,并设置数据源和委托手册。这更灵活,使您能够创建自己的实现UITableViewDataSource的类和代表。