首页 > 其他 > 详细

Type mytableview does not confirm to portocol UITableViewDataResource

时间:2016-11-13 18:54:40      阅读:247      评论:0      收藏:0      [点我收藏+]

技术分享

继承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

原文:http://www.cnblogs.com/ycclmy/p/6059339.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!