2017-01-26 4 views
0
extension FormViewController : UITableViewDelegate { 
    public func tableView(tableView: UITableView, willSelectRowAtIndexPath indexPath: NSIndexPath) -> NSIndexPath? 
    public func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) 
    public func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
    public func tableView(tableView: UITableView, estimatedHeightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat 
    public func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? 
    public func tableView(tableView: UITableView, viewForFooterInSection section: Int) -> UIView? 
    public func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat 
    public func tableView(tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat 
} 

extension FormViewController : UITableViewDataSource { 
    public func numberOfSectionsInTableView(tableView: UITableView) -> Int 
    public func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
    public func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    public func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? 
    public func tableView(tableView: UITableView, titleForFooterInSection section: Int) -> String? 
} 

class NotifiableFormViewController: FormViewController 

DataSourceとTableViewDelegateを実装してオーバーライドできないのはなぜですか?エラー:「メソッドはそのスーパークラスメソッドをオーバーライドしません」UITableViewDataSourceとUITableViewDelegateをオーバーライドできません

class FriendsTableViewController: NotifiableFormViewController{ 
    override func numberOfSections(in tableView: UITableView) -> Int { 
     return 3 
    } 

    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
     return 5 
    } 

    override func tableView(tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "LabelCell", for: indexPath) 

     cell.textLabel?.text = "Section \(indexPath.section) Row \(indexPath.row)" 

     return cell 
    } 

    override func tableView(tableView: UITableView, titleForHeaderInSection section: Int) -> String? { 
     return "Section \(section)" 
    } 
} 
+0

これは助けになるかもしれません:http://stackoverflow.com/a/31432610/656600 – rptwsthi

+0

私はそれを延長内に残す必要があります – UnRewa

+0

[Swift拡張でのメソッドのオーバーライド]の可能な複製(http://stackoverflow.com/questions/38213286/swift-extensionsのoverriding-methods) – Koraktor

答えて

0

定義により、拡張機能は既存のクラスにのみ機能を追加できます。既存の実装を変更することはできません。私はこれが役立つことを願っています

0

UITableViewDataSourceUITableViewDelegateはちょうどプロトコル あなたはそれを上書きしたい場合は、あなたがNotifiableFormViewController

で上記の機能を実装しているあなたがメソッドをオーバーライドしていないので、あなたはそれを実装している単語 overrideを削除

FriendsTableViewController

スーパークラスに実装されていない場合は、オーバーライドできません(実装されたデリゲートまたはデータソース関数をオーバーライドしません)

関連する問題