cannot conform to protocol 的一点事
学习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 的一点事的更多相关文章
- Type '' cannot conform to protocol '' because it has requirements that cannot be satisfied
我有一个Objective-C协议,我试图在Swift类中实现.例如: @class AnObjcClass; @protocol ObjcProtocol <NSObject> - (v ...
- webpack 代码分割一点事
webpack 俨然已经成为前端最主流的构建工具,其功能多种多样,我们今天就来分析下关于代码分割这部分的一点事,并在最后讲述如何实现在webpack编译出的代码里手动添加一个异步chunk. 什么是c ...
- type 'simple Class' does not conform to protocol 'Example Protocol'错误
在看swift教程中"接口和扩展"这小部分. 在编写时提示"type 'simple Class' does not conform to protocol 'Examp ...
- seajs的那点事(很坑的事),和本白的一点事(更坑的事)
在开始之前,偶先吐槽加逗比一下,2天前,CCAV的本白和百度的菊花成功潜入到了携程大楼 然后在没有找到他们运维的情况下,四处乱逛,企图把他们的服务器给root一下,然后再瞎逛之后到了一个很神奇的地方 ...
- 'String' does not conform to protocol 'CollectionType' Error in Swift 2.0
如下是报错需要修改的源码: // if count(currentPassword) < 6 || count(newPassword) < 6 || count(confirmPassw ...
- Swift 给UITableView 写extension 时 报错 does not conform to protocol 'UITableViewDataSource'
那是因为你没有实现 数据源和代理方法 实现下就好了 func tableView(_ tableView: UITableView, numberOfRowsInSection section: In ...
- Ubuntu 18.10 安装之后做的一点事
sb_release -c //查看系统代号 #更新源/etc/apt/sources.list //打开更新目录 deb https://linux.xidian.edu.cn/mirrors/ub ...
- protocol(协议) 和 delegate(委托)也叫(代理)---辨析
protocol和delegate完全不是一回事. 协议(protocol),(名词)要求.就是使用了这个协议后就要按照这个协议来办事,协议要求实现的方法就一定要实现. 委托(delegate),(动 ...
- 关于 object-c的@protocol的理解
从java角度来理解 @protocol 相当于 java 的接口定义,用法也一样 下面是试验例子 @protocol mytestClass <NSObject> - (void) ca ...
随机推荐
- lintcode:1-10题
难度系数排序,容易题1-10题: Cosine Similarity new Fizz Buzz O(1)检测2的幂次 x的平方根 不同的路径 不同的路径 II 两个字符串是变位词 两个 ...
- 【Linux高频命令专题(12)】touch.md
概述 一般在使用make的时候可能会用到,用来修改文件时间,或者新建一个不存在的文件. 命令格式 touch [选项]... 文件... 命令参数 -a 或--time=atime或--time=ac ...
- 函数执行到return就结束了
遇到return,函数就结束了,不会往下执行 测试: class User { String name; int age; boolean fun1(int i){ if(i==1){ return ...
- Hibernate 主键策略
Hibernate主键生成策略 .自动增长identity 适用于MySQL.DB2.MS SQL Server,采用数据库生成的主键,用于为long.short.int类型生成唯一标识 使用SQL ...
- JDBC学习总结(五)
取得数据库连接是件耗时间及资源的动作,尽量利用已打开的连接,也就是重复利用取得的Connection实例,是改善数据库连接性能的一个方式,而采用连接池是基本做法.由于取得Connection的方式根据 ...
- js问题总结
.removeClass(" ") 移除一个css样式 $("#popUpBox i").removeClass("channel_icon" ...
- 三星原厂就K9K8G08U0D升级为K9K8G08U0E的回信
1. please check the below timing first. K9F1G08U0E vs K9F1G08U0D Timing difference tR tPROG tBERS N ...
- HDU 4565 So Easy!(矩阵)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4565 题意: 题意: #include <iostream>#include <cs ...
- 【Latex】如何在Latex中插入伪代码 —— clrscode3e
1. 简介clrscode3e是<算法导论(第三版)>使用的伪代码的宏包,clrs其实表示的是Cormen.Leiserson.Rivest和Stein.它有个更老的版本clrscode, ...
- Effective C++学习笔记 条款06:如不想使用编译器自动生成的函数,就该明确拒绝
一.为驳回编译器自动提供的机能,可将相应成员函数声明为private并且不予实现.(如果你仅仅是自己不实现的话,编译器会帮你实现) 如: class A { public: A(const strin ...