作者satou20444 (希当普利斯)
看板MacDev
标题[问题] UITableView及Cell的问题
时间Mon Feb 15 15:06:12 2016
最近小弟在学习 Objective-C 遇上了一些小问题
已经在 MainStoryBoard 新增两个 Cell (姑且把ID设定为 cellOne 及 cellTwo)
然後在 numberOfRowsInSection 中设定第一个 section return 4
这样第一个 section 就会跑 4 次 cell 到这边的理解应该正确吧 ?
想问的是能够上面两个 row 使用 cellOne 下面两个 row 使用 cellTwo 吗 ?
还是一个 section 只能使用一种 cell 呢 ?
烦请各位解答了 m(_ _)m
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 203.70.195.104
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/MacDev/M.1455519975.A.EC9.html
1F:推 appleway: yes, you can do it. 02/15 15:26
2F:推 www16852: 建立两个cell class? 02/15 16:39
3F:→ www16852: 然後在data source的cellForItemAtIndexPath 02/15 16:42
4F:→ www16852: 加上if let cell as? cellTwo{} 02/15 16:42
5F:→ www16852: 这样吧 02/15 16:42
6F:→ www16852: 阿 我是用swift 你在看看@@ 02/15 16:43
7F:→ LFimi: 在cellForRowAtIndexPath判断条件 return 不同的 cell 02/15 18:25
8F:→ LFimi: 你举的例子大概就是 if (indexPath.row <=1) ... else ... 02/15 18:28
感谢各位,问题已经顺利解决了
後来用
UITableViewCell *cell;
if (indexPath.section == 1 && (indexPath.row == 0 || indexPath.row == 1))
cell = [tableView dequeueReusableCellWithIndentifier:@"cellOne"];
else
cell = [tableView dequeueReusableCellWithIndentifier:@"cellTwo"];
来处理
※ 编辑: satou20444 (203.70.195.104), 02/16/2016 08:25:08