一、创建数据源
self.menuArray = [[NSMutableArrayalloc] initWithCapacity:0];
NSArray *m1Array =@[@{@"name":@"消息中心",@"icon":@"xxzx",@"ctr":@"CYMessageListViewController"},
@{@"name":@"设置",@"icon":@"set",@"ctr":@"MCSettingViewController"}];
[self.menuArrayaddObject:m1Array];
二、创建UITableViewCell
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *Identifier =@"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
[[cell viewWithTag:10]removeFromSuperview];
[[cell viewWithTag:20]removeFromSuperview];
if (!cell) {
cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleValue1reuseIdentifier:Identifier];
cell.backgroundColor = [UIColorwhiteColor];
}
NSArray *funcArray = self.menuArray[indexPath.section];
NSDictionary *menuDit = funcArray[indexPath.row];
cell.textLabel.text = menuDit[@"name"];
cell.textLabel.font = [UIFontsystemFontOfSize:15];
[cell.imageViewsetImage:[UIImageimageNamed:menuDit[@"icon"]]];
cell.detailTextLabel.textColor=EHMO_COLOR_TEXT;
UIImageView *accessoryView=[[UIImageViewalloc]initWithFrame:CGRectMake(WIDTH-30,12.5, 20, 20)];
accessoryView.tag=10;
accessoryView.image=[UIImageimageNamed:@"btn-more_g@2x"];
[celladdSubview:accessoryView];
UILabel *detailLabel=[[UILabelalloc] initWithFrame:CGRectMake(WIDTH-130,2.5, 100, 40)];
detailLabel.backgroundColor=[UIColorwhiteColor];
detailLabel.font=[UIFontsystemFontOfSize:13];
detailLabel.textAlignment=NSTextAlignmentRight;
detailLabel.textColor=[UIColorgrayColor];
detailLabel.tag=20;
[celladdSubview:detailLabel];
return cell;
}
实现效果图: