使用xib自定义Cell

来源:互联网 发布:知乎台湾男生 编辑:程序博客网 时间:2024/04/29 13:09

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

{

    //"myCell"为复用的名字

    UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"myCell"];

    if (cell == nil) {

        

        //"myCell"xib的名字

        cell = [[[NSBundlemainBundle] loadNibNamed:@"myCell"owner:selfoptions:nil]lastObject];

       NSLog(@"创建");

    }else{

       NSLog(@"复用");

    }

    

    

    //number  name  moumouxib上的UIlable控件

    UILabel *number = (UILabel *)[cellviewWithTag:100];

    number.text = [NSStringstringWithFormat:@"学号%d",indexPath.row];

    

    UILabel *name = (UILabel *)[cellviewWithTag:101];

    name.text = [NSStringstringWithFormat:@"姓名%d",indexPath.row];  

    

    UILabel *moumou = (UILabel *)[cellviewWithTag:102];

    moumou.text = [NSStringstringWithFormat:@"某某%d",indexPath.row];

    

    UIImageView *imageView = (UIImageView *)[cellviewWithTag:103];

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

    

    return cell;

    

}

原创粉丝点击