“IOS”开发中,有关UITableView方面的空件的使用!

关于“UITableView”;

1.UIITable的创建:

UITableView *table = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 320, self.view.frame.size.height - 64) style:UITableViewStylePlain];

    [table setRowHeight:44];//设置行高度

    [table setSeparatorColor:[UIColor redColor]];//设置间隔线的颜色


2.在UITableView中添加UIImageView:

UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 132)];

    //[imageView setBackgroundColor:[UIColor redColor]];

    [imageView setImage:[UIImage imageNamed:@"1.png"]];

    [table setTableHeaderView:imageView];

    [imageView release];//必须释放


UITableView的一些属性:

1.设置头标题的名称

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

{

    return @"名称";

}


2.设置头标题的高度

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

    return 44;

}


3.设置脚标题的名称

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

{

    return @"进入";

}

4.设置脚标题的高度

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

{

    return 44;

}

5.右侧添加一个索引表“A-Z”,方便查找

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

{

    NSMutableArray *arr = [NSMutableArray array];

    for (int i = 65; i <= 90; i++) {

        [arr addObject:[NSString stringWithFormat:@"%c", i]];

    }

    return arr;

}


6.设置不同的“A-Z”中各个索引中的成员个数

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

    //NSLog(@"%s",__func__);

    //return [_tableArray count];//任意数值,数值

    if (section == 0) {

        return 3;

    }else if (section == 1){

        return 2;

    }

    return [_tableArray count];

}




7. 设置行高

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{

//    if (indexPath.section == 0) {

//        if (indexPath.row == 0) {

//            return 44;

//        }else if (indexPath.row == 1){

//            return 88;

//        }else if (indexPath.row == 2){

//            return 100;

//        }else if (indexPath.row == 3){

//            return 120;

//        }

//    }//可以根据不同的情况,设置不同的行高

    return 44;

}

UITableView中必须遵循和实现的两个协议:

UITableViewDelegate

UITableViewDataSource;


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

    return 26;//必须有返回值

}


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

    //NSLog(@"%s",__func__);

    static NSString *cellIdentify = @"cellIdentify";//static是设置的全局变量

    TableViewCell *cell = [tableView dequeueReusableHeaderFooterViewWithIdentifier:@"cellIdentify"];//去以key值命名的重用池里取self

    if (!cell) {

        cell = [[[TableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify] autorelease];//创建一个self,并且把重命名的key放到重用池里面

    }

    NSLog(@"section == %d,row == %d",indexPath.section,indexPath.row);

    NSString *str = [_tableArray objectAtIndex:indexPath.row];

    [cell.titleLabel setText:str];

    return cell;

}






  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值