UITableView(基本)--补全分割线 _tableView.separatorInset =UIEdgeInsetsZero

来源:互联网 发布:淘宝手机优惠券 编辑:程序博客网 时间:2024/05/18 20:53

#import "ViewController.h"


@interfaceViewController ()<UITableViewDelegate,UITableViewDataSource>{

   UITableView* _tableView;

}


@end


@implementation ViewController


- (void)viewDidLoad {

    [superviewDidLoad];

    

    _tableView = [[UITableViewalloc]initWithFrame:self.view.boundsstyle:UITableViewStylePlain];

    _tableView.delegate =self;

    //数据源

    _tableView.dataSource =self;

    [self.viewaddSubview:_tableView];

    [_tableView release];

    

    //背景视图

    UIImageView* imageView = [[UIImageViewalloc]initWithFrame:self.view.bounds];

    imageView.image = [UIImageimageNamed:@"10_0.jpg"];

    //_tableView.backgroundView = imageView;

    [imageViewrelease];

    

   //行高

    _tableView.rowHeight =100;

    //分割线类型

    //_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    //分割线颜色

    _tableView.separatorColor = [UIColorblueColor];

    //分割线Inset

    _tableView.separatorInset =UIEdgeInsetsZero;

    

    //重新加载数据

    //[_tableView reloadData];

}


//添加索引

- (NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView{

    return@[@"a",@"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j"];

}


//组和索引对应关系

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{

   NSLog(@"%@---%ld", title, index);

   return index;

}


//多少组

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return10;

}


//组头标题

- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    return [NSStringstringWithFormat:@"%ld", section];

}


//组头视图

- (UIView*)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{

    UILabel* label = [[UILabelalloc]initWithFrame:CGRectMake(0,0, tableView.frame.size.width,50)];

    label.text = [NSStringstringWithFormat:@"组视图%ld", section];

   return [labelautorelease];

}


//组头高度

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

    return50;

}


//组尾标题

- (NSString*)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{

    return [NSStringstringWithFormat:@"end%ld",section];

}


//组尾视图

//- (UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{

//

//}


//组尾高度

//- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{

//

//}


//必须实现的方法

//多少行

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

   if (section ==0) {

       return5;

    }elseif (section ==1){

       return10;

    }

    return20;

}


- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    //队列描述符

   staticNSString* ID =@"ID";

    //ID队列里面去获取Cell

    UITableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:ID];

    //如果为空,队列里面是没有的,创建一个cell

   if (cell ==nil) {

        //1.类型 2.队列

        //当出了屏幕以后,cell会自动保存到名字叫做ID的队列中

        cell = [[[UITableViewCellalloc]initWithStyle:UITableViewCellStyleSubtitlereuseIdentifier:ID]autorelease];

       //选中样式

        //cell.selectionStyle = UITableViewCellSelectionStyleNone;

       //选中背景视图

        UIImageView* imageView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0, tableView.frame.size.width, tableView.rowHeight)];

        imageView.image = [UIImageimageNamed:@"Nav_Bg.png"];

        cell.selectedBackgroundView = imageView;

        [imageViewrelease];

       //扩展类型

        cell.accessoryType =UITableViewCellAccessoryDetailButton;

       //扩展视图

       UISwitch* mySwitch = [[UISwitchalloc]init];

        cell.accessoryView = mySwitch;

        

//        UILabel* label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 100, 30)];

//        label.tag = 10;

//        [cell addSubview:label];

//        [label release];

    }

//    UILabel* label = (UILabel*)[cell viewWithTag:10];

//    label.text = [NSString stringWithFormat:@"%ld",indexPath.row];


   

    cell.textLabel.text = [NSStringstringWithFormat:@"%ld",indexPath.row];

    cell.detailTextLabel.text =@"副标题/详情...";

    cell.imageView.image = [UIImageimageNamed:@"gerenzhuye.png"];

    

    

   return cell;

}


- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{

   NSLog(@"点击了第%ldButton", indexPath.row);

}


//选中一行调用

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

   NSLog(@"选中%ld组的%ld", indexPath.section, indexPath.row);

}


//隐藏状态栏

- (BOOL)prefersStatusBarHidden{

    returnYES;

}


@end


0 0
原创粉丝点击