您的位置:首页 > 产品设计 > UI/UE

Type mytableview does not confirm to portocol UITableViewDataResource

2016-11-13 17:47 295 查看


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

}

}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐