//
// ViewController.m
// SingleLine
//
// Created by Tony on 15/1/8.
// Copyright (c) 2015年 Tony. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
{
NSArray *arr;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UITableView *table = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
table.delegate = self;
table.dataSource = self;
table.backgroundColor = [UIColor clearColor];
table.separatorStyle = UITableViewCellSeparatorStyleNone;
arr = [NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5", nil];
[self.view addSubview:table];
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (!cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
//核心语句
<span style="color:#FF0000;">if ([tableView numberOfRowsInSection:indexPath.section] > 1 && !(indexPath.row == arr.count -1) ) {
[self setSingleLine:cell];
}</span>
cell.textLabel.text = [arr objectAtIndex:indexPath.row];
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 44;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return arr.count;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = nil;
return view;
}
- (void)setSingleLine:(UITableViewCell*)cell{
UIImageView *lingImage = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"DefaultLine"]];
lingImage.frame = CGRectMake(10, 44 - 1, self.view.bounds.size.width - 20, 1);
lingImage.opaque = YES;
[cell.contentView addSubview:lingImage];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
tableview 多行情况下 最后一行不加线条 如果有一行也不加
最新推荐文章于 2020-07-04 10:16:36 发布
