tableview 多行情况下 最后一行不加线条 如果有一行也不加

本文将介绍如何使用Objective-C语言进行iOS应用开发,包括基本语法、开发环境配置、常见框架使用及实战案例分析。
//
//  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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值