码迷,mamicode.com
首页 > 其他好文 > 详细

Type mytableview does not confirm to portocol UITableViewDataResource

时间:2016-11-13 18:57:53      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:ati   alt   table   cts   orm   awr   number   copyright   source   

技术分享

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

标签:ati   alt   table   cts   orm   awr   number   copyright   source   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!