IOS-static cell 与 dynamic cell 混合使用
static cell 与 dynamic cell 混合使用
在某些界面中static cell与dynamic cell混合使用会事半功倍,比如手机上的Wi-Fi
功能等,效果图如下:
Wi-Fi
界面的第一组与第三组的行数都是固定的,且布局并不相同,类似这样的布局使用static cell很快就可以完成,然而第二组却需要使用dynamic cell。这时候就会用到静态cell与动态cell混合使用的情况。
首先,在Storyboard中添加一个UITableViewController,设置为Static cell,并设置好第一组与第三组的内容,第二组需要设置一个空的Cell,如图:
然后,给第二组的空白Cell设置identifier值,如图:
然后,第二组需要自定义cell,这里使用XIB来完成,如图:
接下来需要用代码注册Nib,如下:
let nib = UINib(nibName: "WiFiTableViewCell", bundle: nil)
tableView.registerNib(nib, forCellReuseIdentifier: "WiFiTableViewCell")
最后,为了让 static cell 与 dynamic cell 能够混合使用,需要实现TableView的代理,代码如下:
// 以下代理方法必须实现
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if indexPath.section == {
let cell = tableView.dequeueReusableCellWithIdentifier("WiFiTableViewCell") as? WiFiTableViewCell
return cell!
}
return super.tableView(tableView, cellForRowAtIndexPath: indexPath)
} override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
if section == {
return //这里返回第二组的行数
}
return super.tableView(tableView, numberOfRowsInSection: section)
} override func tableView(tableView: UITableView, indentationLevelForRowAtIndexPath indexPath: NSIndexPath) -> Int {
if indexPath.section == {
return super.tableView(tableView, indentationLevelForRowAtIndexPath: NSIndexPath(forRow: , inSection: ))
}
return super.tableView(tableView, indentationLevelForRowAtIndexPath: indexPath)
} override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath.section == {
return
}
return super.tableView(tableView, heightForRowAtIndexPath: indexPath)
}
值得注意的是:
- 在storyboard中需要给第二组设置一行空的Cell,并设置identifier值。
- 在代码中也需要注册Cell
- 上面提到的代理方法必须实现
最后,本文主要是记录关于 static cell 与 dynamic cell 的混合使用,因此很多细节问题并没有处理,更多关于static cell另外的一些使用,可以点击这里【更优雅地使用Static Cell】
原文链接:http://www.jianshu.com/p/c3645c13af4b
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
IOS-static cell 与 dynamic cell 混合使用的更多相关文章
- iOS学习之UI自定义cell
一.自定义Cell 为什么需要自定义cell:系统提供的cell满足不了复杂的样式,因此:自定义Cell和自定义视图一样,自己创建一种符合我们需求的Cell并使用这个Cell.如下图所示的这些Cell ...
- ios之UI中自定义cell
*:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...
- iOS学习之UITableView中Cell的操作
接着iOS学习之Table View的简单使用 这篇,这里主要讲UITableView 中的Cell的操作,包括标记.移动.删除.插入. 为了简单快捷,直接从原来那篇的代码开始,代码下载地址:http ...
- iOS开发UITableView的动画cell
1.动画cell 针对cell的动画,在Delegate中对cell的layer进行操作: 2.实现代码 #import "ViewController.h" #import &q ...
- iOS开发总结-UITableView 自定义cell和动态计算cell的高度
UITableView cell自定义头文件:shopCell.h#import <UIKit/UIKit.h>@interface shopCell : UITableViewCell@ ...
- ios 获取button所在的cell对象, 注意:ios7 =< System Version < ios8 获取cell对象的差别
ios7 =< System Version< ios8 : ios7 =< System Version < ios8 下 button.superview.supervi ...
- UITableView错误 ‘unable to dequeue a cell with identifier Cell'
- (id)dequeueReusableCellWithIdentifier:(NSString *)identifier; - (id)dequeueReusableCellWithIdentif ...
- reason: 'unable to dequeue a cell with identifier Cell
今天在cell重用的时候出现一下错误 reason: 'unable to dequeue a cell with identifier Cell - must register ...
- IOS开发之UITabBarController与UINavigationController混合使用
ios开发中UITabBarController与UINavigationController混合使用是很多app的基础页面结构,下面是简单的的页面初始化的方法,在AppDelegate.m的 - ( ...
随机推荐
- WebSocket client for python
Project description websocket-client module is WebSocket client for python. This provide the low lev ...
- python三层架构
conf/setting(配置文件) 一般是对utility进行相关设置 index(主文件) main函数触发某个对象的业务逻辑方法 model(数据库) admin 是对数据库的操 ...
- 洛谷P1156 垃圾陷阱 dp
正解:dp 解题报告: 这儿是传送门! 话说最近怎么神仙们都开始狂刷dp,,,感觉今天写了好多dp的题解的样子?(也就三四道其实× 然后这题,首先看到要么吃要么堆起来就会想到01背包趴?然后就考虑设方 ...
- appfog 添加数据库支持
1.PhpMyAdmin与app 在同一应用 1.cd进入应用所在的文件夹,输入 git clone git://github.com/appfog/af-php-myadmin.git 2.进入本地 ...
- 新安装和已安装nginx如何添加未编译安装模块/补丁
新安装和已安装nginx如何添加未编译安装模块/补丁 --http://www.apelearn.com/bbs/forum.php?mod=viewthread&tid=10485& ...
- 江苏新美星智能物流无人叉车AGV
新美星一家全球领先的液体包装解决方案供应商,高附加值的产品应用于食品饮料等行业,为液体食品和自动化系统提供完整解决方案.新美星,于CBST2017展会首次亮相了能够从仓库或工厂的某个地方把材料.托盘和 ...
- Selenium之IE浏览器的启动
1.下载IEDriverServer.exe文件放至需要的目录中: 2.编写代码 import org.openqa.selenium.WebDriver; import org.openqa.sel ...
- 通过CFX发布WebService(一)
发布WebService的方法很多.如XFire,CFX等.现在首先介绍下怎样通过CFX来发部一个WebService. (1) 首先,是从Apache官方网站获取CFX的Java包.其地址是:htt ...
- 企业级服务元年:iClap高效解决手游更新迭代问题
2006年至今,手游市场经历了不少变革,从WAP站到2009年智能手机时代来临,2012大量资本涌入国内手游行业,到2014年手游市场趋于成熟,细分市场成为追逐热门,在2015年优胜劣汰的资本寒冬浪潮 ...
- asp.net 获取mp3 播放时长
1 Shell32 //添加引用:COM组件的Microsoft Shell Controls And Automation //然后引用 using Shell32; //如果出现“无法嵌入互操作类 ...