学习UITableView过程中,回想视频打一遍代码,发现卡在了第一步。一直显示无法继承协议,而且还多了一个错误:definition conflicts with previous value。百度上也找不到什么原因,仔细一想才发现方法写错地方,看来很多错误还是出现在自己身上。要细心才行。以下是错误的示范:

class ViewController: UIViewController, UITableViewDelegate ,UITableViewDataSource{
    @IBOutlet var tableView1: UITableView!
    override func viewDidLoad() {
        super.viewDidLoad()
        tableView1.dataSource = self
        tableView1.delegate = self
    func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return 20
    }
    func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
        let cell = UITableViewCell(frame: CGRect(x: 0, y: 0, width: 320, height: 48))
        cell.detailTextLabel?.text = "By bitos"
        cell.textLabel?.text = "hello Bibi"
        return cell
    }//错误提示:definition conflicts with previous value
    }
 

正确姿势应该是这样的:

class ViewController: UIViewController, UITableViewDelegate ,UITableViewDataSource{

    @IBOutlet var tableView1: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib. tableView1.dataSource = self
tableView1.delegate = self }
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return
} func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(frame: CGRect(x: , y: , width: , height: ))
cell.detailTextLabel?.text = "By bitos"
cell.textLabel?.text = "hello Bibi"
return cell
}

切记切记

cannot conform to protocol 的一点事的更多相关文章

  1. Type '' cannot conform to protocol '' because it has requirements that cannot be satisfied

    我有一个Objective-C协议,我试图在Swift类中实现.例如: @class AnObjcClass; @protocol ObjcProtocol <NSObject> - (v ...

  2. webpack 代码分割一点事

    webpack 俨然已经成为前端最主流的构建工具,其功能多种多样,我们今天就来分析下关于代码分割这部分的一点事,并在最后讲述如何实现在webpack编译出的代码里手动添加一个异步chunk. 什么是c ...

  3. type &#39;simple Class&#39; does not conform to protocol &#39;Example Protocol&#39;错误

    在看swift教程中"接口和扩展"这小部分. 在编写时提示"type 'simple Class' does not conform to protocol 'Examp ...

  4. seajs的那点事(很坑的事),和本白的一点事(更坑的事)

    在开始之前,偶先吐槽加逗比一下,2天前,CCAV的本白和百度的菊花成功潜入到了携程大楼 然后在没有找到他们运维的情况下,四处乱逛,企图把他们的服务器给root一下,然后再瞎逛之后到了一个很神奇的地方 ...

  5. 'String' does not conform to protocol 'CollectionType' Error in Swift 2.0

    如下是报错需要修改的源码: // if count(currentPassword) < 6 || count(newPassword) < 6 || count(confirmPassw ...

  6. Swift 给UITableView 写extension 时 报错 does not conform to protocol 'UITableViewDataSource'

    那是因为你没有实现 数据源和代理方法 实现下就好了 func tableView(_ tableView: UITableView, numberOfRowsInSection section: In ...

  7. Ubuntu 18.10 安装之后做的一点事

    sb_release -c //查看系统代号 #更新源/etc/apt/sources.list //打开更新目录 deb https://linux.xidian.edu.cn/mirrors/ub ...

  8. protocol(协议) 和 delegate(委托)也叫(代理)---辨析

    protocol和delegate完全不是一回事. 协议(protocol),(名词)要求.就是使用了这个协议后就要按照这个协议来办事,协议要求实现的方法就一定要实现. 委托(delegate),(动 ...

  9. 关于 object-c的@protocol的理解

    从java角度来理解 @protocol 相当于 java 的接口定义,用法也一样 下面是试验例子 @protocol mytestClass <NSObject> - (void) ca ...

随机推荐

  1. lintcode 中等题:majority number III主元素III

    题目 主元素 III 给定一个整型数组,找到主元素,它在数组中的出现次数严格大于数组元素个数的1/k. 样例 ,返回 3 注意 数组中只有唯一的主元素 挑战 要求时间复杂度为O(n),空间复杂度为O( ...

  2. Unity UGUI —— 鼠标穿透UI问题(Unity官方的解决方法)

    解决方案 : http://www.cnblogs.com/fly-100/p/4570366.html 这里我们直接在使用Input.GetMouseButtonDown(0)的地方加了一个检测函数 ...

  3. Orcle数据库查询练习复习:四

    一.题目 1.找出张三的最高分和最低分以及对应的课程名 select * from course c,mark m where c.cid=m.cid and sid =(select sid fro ...

  4. 查看Linux版本系统信息方法汇总

    Linux下如何查看版本信息, 包括位数.版本信息以及CPU内核信息.CPU具体型号等等,整个CPU信息一目了然.  1.# uname -a   (Linux查看版本当前操作系统内核信息)  Lin ...

  5. BZOJ 2440 完全平方数(莫比乌斯-容斥原理)

    题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2440 题意:给定K.求不是完全平方数(这里1不算完全平方数)的倍数的数字组成的数字集合S ...

  6. jQuery--隐藏事件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  7. Provider Pattern提供者模式和策略模式

    http://www.codeproject.com/Articles/18222/Provider-Pattern Introduction Provider pattern is one of t ...

  8. 1218. Episode N-th: The Jedi Tournament(bfs)

    1218 简答题 对于当前点 判断每个点是否可达 #include <iostream> #include<cstdio> #include<cstring> #i ...

  9. 教你如何将 Sublime 3 打造成 Python/Django IDE开发利器

    Sublime Text 是一款非常强大的文本编辑器, 下面我们介绍如何将 Sublime Text 3 打造成一款 Python/Django 开发利器: 1. 安装 Sublime Text 3 ...

  10. "xxxx".zip:这个压缩文件格式未知或者数据已经被损坏,打不开压缩文件,总出现这个提示的解决方法

    从网上下载了一些压缩文件,有时解压时会出现“这个压缩文件格式未知或者数据已经被损坏”或“未找到压缩文件”的提示. 造成的原因有两种: 一.网站上的压缩文件本来就是坏的. 1.你可以尝试可以使用WINR ...