老师您好,第一个cell是value1样式,剩下的cell是subtitle样式,怎么实现

老师您好,第一个cell是value1样式,剩下的cell是subtitle样式,怎么实现

老师您好,第一个cell是value1样式,剩下的cell是subtitle样式,怎么实现

正在回答 回答被采纳积分+1

登陆购买课程后可参与讨论,去登陆

2回答
提问者 慕粉1472629313 2018-11-05 18:17:24

http://img1.sycdn.imooc.com//climg/5be018760001100907501333.jpg右边的加减号控制中间的数字怎么实现呢

  • 你可以添加一个UILabel或者是UITextField控件去显示value值。
    2018-11-05 18:28:28
Tender10 2018-11-05 14:05:22

在cellForRowAtIndexPath方法里,根据indexPath进行判断,然后判断是第几行,设置不同的cell样式就可以啦。

  • 提问者 慕粉1472629313 #1
    cell的是哪个属性呢, -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"UITableViewCell"]; if (!cell) { cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"UITableViewCell"]; } cell.accessoryView = nil; if (indexPath.row == 0) { cell.textLabel.text = @"京东E卡"; cell.textLabel.font = [UIFont systemFontOfSize:11]; cell.textLabel.textColor = [UIColor colorWithRed:42/255. green:45/255. blue:52/255. alpha:1]; cell.detailTextLabel.text = @"使用说明"; cell.detailTextLabel.font = [UIFont systemFontOfSize:11]; cell.detailTextLabel.textColor = [UIColor colorWithRed:42/255. green:45/255. blue:52/255. alpha:1]; cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; } else{ cell.imageView.image = [UIImage imageNamed:@"jingdong_50"]; cell.textLabel.text = @"电子京东E卡50元"; cell.textLabel.font = [UIFont systemFontOfSize:11]; cell.textLabel.textColor = [UIColor colorWithRed:42/255. green:45/255. blue:52/255. alpha:1]; cell.detailTextLabel.text = @"55金币"; cell.detailTextLabel.font = [UIFont systemFontOfSize:11]; cell.detailTextLabel.textColor = [UIColor colorWithRed:42/255. green:45/255. blue:52/255. alpha:1]; } return cell; }
    2018-11-05 15:22:04
  • Tender10 回复 提问者 慕粉1472629313 #2
    这个就相当于你设置两个cell样式啊,所以判断indexPath.row==0的时候,就设置cell的样式为value1的,并且进行相关属性的赋值。如果indexPath.row不是0,就设置cell的样式为subtitle。
    2018-11-05 15:42:26
  • 提问者 慕粉1472629313 回复 Tender10 #3
    思路我明白的 我的意思是 假如我想设置cell的背景颜色,代码是 cell.backgroundcolor= [uicolor redcolor]; 设置cell的样式代码是什么呢? cell. ?
    2018-11-05 16:14:37
问题已解决,确定采纳
还有疑问,暂不采纳

恭喜解决一个难题,获得1积分~

来为老师/同学的回答评分吧

0 星
iOS进阶:界面优化与数据存储
  • 参与学习       516    人
  • 提交作业       158    份
  • 解答问题       637    个

本路径采用基础+案例方式,助你解开对界面优化、数据储存、屏幕适配的疑惑。6小时团购项目实战加最新版本Swift讲解,让你掌握更多iOS开发技巧。

了解课程
请稍等 ...
意见反馈 帮助中心 APP下载
官方微信

在线咨询

领取优惠

免费试听

领取大纲

扫描二维码,添加
你的专属老师