第一步:

  1. //UserTableViewCell.h这里定义第一种Cell
  2. #import <UIKit/UIKit.h>
  3. @interface UserTableViewCell : UITableViewCell
  4. @property (weak, nonatomic) IBOutlet UIImageView *userviewcellicon;
  5. @property (weak, nonatomic) IBOutlet UILabel *userviewcellname;
  6. @end
  7. //UserTableViewCell2.h这里定义第二种Cell,
  8. #import <UIKit/UIKit.h>
  9. @interface UserTableViewCell2 : UITableViewCell
  10. @property (weak, nonatomic) IBOutlet UILabel *name;
  11. @property (weak, nonatomic) IBOutlet UIImageView *userviewcell2image;
  12. @end

故事板里的TableView和Cell的class和Cell的Identifier就不说了

  1. 、设计好了这些东西后,开始进TableViewController里了:
  2. //UserTableViewController.h
  3. #import <UIKit/UIKit.h>
  4.  
  5. @interface UserTableViewController : UITableViewController
  6.  
  7. @property(nonatomic,strong) NSDictionary *UserViewCellDic;
  8. @property (nonatomic, strong) NSArray *listGroupname;
  9. @end
  10. //UserTableViewController.m
  11. #import “UserTableViewController.h“
  12. #import “UserTableViewCell.h“
  13. #import “UserTableViewCell2.h“
  14. @interface UserTableViewController ()
  15.  
  16. @end
  17.  
  18. @implementation UserTableViewController
  19.  
  20. - (void)viewDidLoad
  21. {
  22. [super viewDidLoad];
  23. self.tableView.separatorStyle = UITableViewCellAccessoryNone;//去除分割线
  24. NSBundle *bundle = [NSBundle mainBundle];
  25. NSString *plistpath = [bundle pathForResource:@”UserViewCell ofType:@”plist“];
  26. self.UserViewCellDic = [[NSDictionary alloc]initWithContentsOfFile:plistpath];
  27. self.listGroupname = [self.UserViewCellDic allKeys];
  28.   
  29. self.listGroupname = [self.listGroupname sortedArrayUsingSelector:@selector(compare:)];//排序
  30. }
  31.  
  32. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView//返回有几个Section
  33. {
  34.  
  35. return [self.listGroupname count];
  36. }
  37.  
  38. - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section//Section头名字设为空
  39. {
  40.  
  41. NSString *groupName = @” “;
  42. return groupName;
  43. }
  44.  
  45. - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//每个section的行数
  46. {
  47.  
  48. NSString *groupName = [self.listGroupname objectAtIndex:section];
  49. NSArray *listitem = [self.UserViewCellDic objectForKey:groupName];
  50. return [listitem count];
  51.  
  52. }
  53. #pragma mark TableViewDataSource
  54.  
  55. - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
  56. {
  57.  
  58. static NSString *UserViewCellIdentifier = @”UserTableViewCell“;
  59. static NSString *UserViewCellIdentifier2 = @”UserTableViewCell2“;
  60. NSUInteger section = [indexPath section];
  61. NSUInteger row = [indexPath row];
  62. NSString *groupName = [self.listGroupname objectAtIndex:section];
  63. NSArray *listitem = [self.UserViewCellDic objectForKey:groupName];
  64. NSDictionary *rowDict = [listitem objectAtIndex:row];
  65.  
  66. if ( == section) {
  67. UserTableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:UserViewCellIdentifier2];
  68. cell.name.text = [rowDict objectForKey:@”name“];
  69. NSString *imagePath = [rowDict objectForKey:@”image“];
  70. imagePath = [imagePath stringByAppendingString:@”.png“];
  71. cell.userviewcell2image.image = [UIImage imageNamed:imagePath];
  72. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//最后的箭头
  73. //画线
  74. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
  75. UIView *leftview = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
  76. UIView *rightview = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
  77. view.backgroundColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:];
  78. leftview.backgroundColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:];
  79. rightview.backgroundColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:];
  80. [cell.contentView addSubview:view];
  81. [cell.contentView addSubview:leftview];
  82. [cell.contentView addSubview:rightview];
  83.  
  84. return cell;
  85. }else{
  86. UserTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:UserViewCellIdentifier];
  87. cell.userviewcellname.text = [rowDict objectForKey:@”name“];
  88. NSString *imagePath = [rowDict objectForKey:@”image“];
  89. imagePath = [imagePath stringByAppendingString:@”.png“];
  90. cell.userviewcellicon.image = [UIImage imageNamed:imagePath];
  91. cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//最后的箭头
  92. //画线
  93. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
  94. UIView *leftview = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
  95. UIView *rightview = [[UIView alloc]initWithFrame:CGRectMake(, , , )];
  96. view.backgroundColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:];
  97. //alpha是透明度
  98. leftview.backgroundColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:0.3];
  99. rightview.backgroundColor = [UIColor colorWithRed:/255.0f green:/255.0f blue:/255.0f alpha:];
  100. [cell.contentView addSubview:view];
  101. [cell.contentView addSubview:leftview];
  102. [cell.contentView addSubview:rightview];
  103.  
  104. return cell;
  105. }
  106.  
  107. }
  108.  
  109. -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath//Cell的高度
  110. {
  111. NSUInteger section = [indexPath section];
  112. if ( == section) {
  113. return ;
  114. }else{
  115. return ;
  116. }
  117.  
  118. }

这里附上Plist文件:

3、运行效果:

[IOS 开发] TableView、多个TableViewCell、自定义Cell、Cell上画画(故事板+代码方式)的更多相关文章

  1. iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局

    iOS开发UI篇—使用xib自定义UItableviewcell实现一个简单的团购应用界面布局 一.项目文件结构和plist文件 二.实现效果 三.代码示例 1.没有使用配套的类,而是直接使用xib文 ...

  2. iOS开发tableView去掉顶部上部空表区域

    tableview中的第一个cell 里上部 有空白区域,大概64像素 在viewDidLoad中加入如下代码 self.automaticallyAdjustsScrollViewInsets = ...

  3. iOS开发UI篇—CAlayer(自定义layer)

    iOS开发UI篇—CAlayer(自定义layer) 一.第一种方式 1.简单说明 以前想要在view中画东西,需要自定义view,创建一个类与之关联,让这个类继承自UIView,然后重写它的Draw ...

  4. iOS开发之网络编程--使用NSURLConnection实现文件上传

    前言:使用NSURLConnection实现文件上传有点繁琐.    本文并没有介绍使用第三方框架上传文件. 正文: 这里先提供用于编码测试的接口:http://120.25.226.186:3281 ...

  5. iOS开发 XML解析和下拉刷新,上拉加载更多

    iOS开发 XML解析和下拉刷新,上拉加载更多 1.XML格式 <?xml version="1.0" encoding="utf-8" ?> 表示 ...

  6. iOS开发-- 如何让 UITableView 的 headerView跟随 cell一起滚动

    在我们利用 UITableView 展示我们的内容的时候,我需要在顶部放一个不同于一般的cell的 界面,这个界面比较独特. 1. 所以我就把它 作为一个section的 headerView. 也就 ...

  7. iOS开发之结合asp.net webservice实现文件上传下载

    iOS开发中会经常用到文件上传下载的功能,这篇文件将介绍一下使用asp.net webservice实现文件上传下载. 首先,让我们看下文件下载. 这里我们下载cnblogs上的一个zip文件.使用N ...

  8. iOS开发 tableView点击下拉扩展 + 内嵌collectionView上传图片效果

    ---恢复内容开始--- //需要的效果 1.设置window的根视图控制器为一个UITableViewController #import "AppDelegate.h"#imp ...

  9. iOS学习——tableview中带编辑功能的cell键盘弹出遮挡和收起问题解决

    最近在项目中经常用到UITableView中的cell中带有UITextField或UITextView的情况,然后在这种场景下,当我们点击屏幕较下方的cell进行编辑时,这时候键盘弹出来会出现遮挡待 ...

随机推荐

  1. JavaScript:this是什么?

    JavaScript:this是什么?定义:this是包含它的函数作为方法被调用时所属的对象.说明:这句话有点咬嘴,但一个多余的字也没有,定义非常准确,我们可以分3部分来理解它! 1.包含它的函数.2 ...

  2. Android的学习第六章(布局一TableLayout)

    今天我们来简单的说一下Android不居中的TableLayout布局(表格布局) 表格布局的意思就是将我们的布局看做为一个表格,主要用于对控件进行整齐排列 我们看一个简单的案例 <TableL ...

  3. h5网页中使用打电话功能

    如果需要在移动浏览器中实现拨打电话,发送email,美国服务器,调用sns等功能,移动手机WEB页面(HTML5)Javascript提供的接口是一个好办法. 采用url链接的方式,实现在Safari ...

  4. shell导出mysql部分数据

    #!/bin/shSYSTEM=`uname -s` echo "echo"$SYSTEM if [[ $SYSTEM = "Linux" ]]; then   ...

  5. 使用JavaScript访问子节点方法elementNode.childNodes时,需要注意的地方

    有这样一个HTML结构 <div> javascript <p>javascript</p> <div>jQuery</div> <h ...

  6. SharePoint常用目录介绍

    SharePoint常用目录介绍 stsadm命令管理程序目录:C:\Program Files\Common Files\Microsoft Shared\web server extensions ...

  7. html5移动端知识点总结

    第一章,控制html字体大小 1.1使用媒体查询,不同分辨率设置不同的html的font-size   @(min-width:320px){ html{font-size:10px;} } @(mi ...

  8. 定长循环队列C语言实现

    #ifndef _CONST_H_#define _CONST_H_ #include <stdio.h>#include <stdlib.h> typedef enum { ...

  9. 使用scp在windows和Linux之间互传文件

    转自:http://yangzhongfei.blog.163.com/blog/static/4610987520103141050918/ 为了进行系统维护操作,有时需要再windows和linu ...

  10. Xcode7 *** does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE)

    *** does not contain bitcode. You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE ...