在iPhone应用的table cell中添加自定义布局view

在iPhone应用的table cell中添加自定义布局view



在iPhone开发中,tableView提供了通过nib自定义视图的解决方案。这就使开发者能够完成相当复杂的界面布局。下面介绍table中添加自定义的table cell。实现的效果如下:

实现过程很简单,首先创建一个table视图,添加table相应的协议。

接下来,新建文件,并在 subclass 里 选择  UITableViewCell 这里我命名为 “MyCell”

然后在利用IB创建一个名为mycell的nib,在里面拖入一个UITableViewCell并将其类名改为MyCell。

 

实现具体的类:

-(NSInteger) tableView:(UITableView *)tableView

numberOfRowsInSection:(NSInteger)section


    return 1; 
}

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

    static NSString *CellIdentifier = @"CustomCellIdentifier"; 
    MyCell *cell = (MyCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"mycell" owner:self options:nil]; 
        cell = [array objectAtIndex:0]; 
        [cell setSelectionStyle:UITableViewCellSelectionStyleGray]; 
    } 
    [[cell lable] setText:@"你好"]; 
    //[[cell imageView] setImage:[UIImage imageNamed:[imageNameArray objectAtIndex:indexPath.row]]]; 
    //[[cell nameLabel] setText:[nameArray objectAtIndex:indexPath.row]]; 
    return cell; 

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

{       
    return 90; 
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值