Type mytableview does not confirm to portocol UITableViewDataResource

Posted 百里抱木

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Type mytableview does not confirm to portocol UITableViewDataResource相关的知识,希望对你有一定的参考价值。

继承UITableViewDataSource报上面这个总是,是重写协议时写错了

override func numberOfRowsInSection(section: Int) -> Int {
        return 3
    }

应该写下面这个

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

就正确了。

代码如下

//
//  MyTableView.swift
//  L02TableView
//
//  Created by Myron on 16/11/13.
//  Copyright © 2016年 Myron. All rights reserved.
//

import UIKit

class MyTableView: UITableView,UITableViewDataSource{

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect) {
        // Drawing code
    }
    */
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.dataSource = self;
    }
    
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 3
    }
    
//    override func numberOfRowsInSection(section: Int) -> Int {
//        return 3
//    }
    
    func numberOfSectionsInTableView(tableView: UITableView) -> Int {
        return 1
    }
    
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = tableView.dequeueReusableCellWithIdentifier("cell")
        
        let label = cell?.viewWithTag(1) as! UILabel
        
        label.text = "Hello Table View"
        
        return cell!
        
    }
    

}

以上是关于Type mytableview does not confirm to portocol UITableViewDataResource的主要内容,如果未能解决你的问题,请参考以下文章

Editor does not contain a main type问题

[WPF]The type name ‘App’ does not exist in the type '...'的问题

Input ‘filename‘ of ‘ReadFile ‘Op has type float32 that does not match expected type of string

Go: invalid operation - type *map[key]value does not support indexing

Input ‘filename‘ of ‘ReadFile ‘Op has type float32 that does not match expected type of string

[ts] Property 'aaa' does not exist on type 'Window' 解决办法