码迷,mamicode.com
首页 > 移动开发 > 详细

iOS开发——UI高级Swift篇&swift简单总结tableView

时间:2015-09-16 21:42:08      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

 swift简单总结tableView
 
 
 
今天来总结一个很简单的问题,真心说出来丢脸,但是由于本人在写swift项目的时候总是发现Xib不能加载,而且不止一次,所以就简单的总结一下!
 
一:简单的使用缓存池
1.设置StoryBoard中cell的ID
技术分享
 
2.在控制器的Cell中就可以直接使用ID创建了
1     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
2         let cell = tableView.dequeueReusableCellWithIdentifier(“iCocos”, forIndexPath: indexPath) as! UITableViewCell
3 
4         cell.textLabel?.text = "iCocos----------ios"
5 
6         return cell
7

 

 
二:使用自定义类实现
1.需要先注册一个Cell并且设置一个ID(这里也可以提前在前面设置好全局常量
技术分享
 
2.在控制器的Cell中就可以直接使用自定义的Cell和ID实现Cell的显示了
1     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
2         let cell = tableView.dequeueReusableCellWithIdentifier(ID, forIndexPath: indexPath) as! iCocosTableViewCell
3 
4         cell.textLabel?.text = "iCocos----------ios"
5 
6         return cell
7     }

 

三:使用自定义类+Xib实现
Xib对应的就是Cell
1.为Xib中的Cell定义一个标志符
技术分享
 
2.在控制里面定义一个全局的常量ID(前面已提到),需要与Xib中的ID一样
技术分享
 
3.注册一个Nib(Xib)使用定义好的ID
技术分享
 
4.最后同意在控制里面实现cell数据的显示
1     override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
2         let cell = tableView.dequeueReusableCellWithIdentifier(ID, forIndexPath: indexPath) as! iCocosTableViewCell
3 
4         cell.textLabel?.text = "iCocos----------ios"
5 
6         return cell
7     }

 

 

 

iOS开发——UI高级Swift篇&swift简单总结tableView

标签:

原文地址:http://www.cnblogs.com/iCocos/p/4814403.html

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