学习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. Project Euler 84:Monopoly odds 大富翁几率

    Monopoly odds In the game, Monopoly, the standard board is set up in the following way:             ...

  2. spring aop通过joinpoint传递参数

    三.总结. 我们可以通过Advice中添加一个JoinPoint参数,这个值会由spring自动传入,从JoinPoint中可以取得. 三.总结. 我们可以通过Advice中添加一个JoinPoint ...

  3. Linux文件系统介绍

    1.ext2/ext3(日志功能)文件系统(Linux标准文件系统.一种索引式文件系统) SuperBlock:Superblock是记录整个filesystem 相关信息的地方,没有Superblo ...

  4. AsyncTask 与 Thread+Handler

    AsyncTask是封装好的线程池,比起Thread+Handler的方式,AsyncTask在操作UI线程上更方便,因为onPreExecute().onPostExecute()及更新UI方法on ...

  5. 深入探索 Java 热部署

    在 Java 开发领域,热部署一直是一个难以解决的问题,目前的 Java 虚拟机只能实现方法体的修改热部署,对于整个类的结构修改,仍然需要重启虚拟机,对类重新加载才能完成更新操作.对于某些大型的应用来 ...

  6. Haxe - Actuate.Tween

    方法解释: Actuate.tween( target : Dynamic , duration : Float , properties : Dynamic , ?overwrite : Bool ...

  7. Java API —— Collections类

    1.Collections类概述         针对集合操作 的工具类,都是静态方法   2.Collections成员方法         public static <T> void ...

  8. Linux Shell脚本读写XML文件

    在Linux下如何用Shell脚本读写XML?现有一个config.xml <?xml version="1.0" encoding="UTF-8"?&g ...

  9. 分布式ActiveMQ集群

    分布式ActiveMQ集群的部署配置细节: 官方资料:http://activemq.apache.org/clustering.html 基本上看这个就足够了,本文就不具体分析配置文件了. 1.Qu ...

  10. Android权限安全(5)组件的android:exported属性

    Android四大组件都有 android:exported 属性 android:exported="true" 时 表示该组件是公开的,其它组件可以访问这个组件 android ...