IOS 自定义cell

不知为什么,用书上的方法无法显示cell

暂记录如下:

新建一个CustomCellVC.h CustomCellVC.m

定义输出口:例如.h:

@property (retain, nonatomic) NSString *clogcode;

@property (retain, nonatomic) IBOutletUILabel *clogcodeLabel;

.m文件重写其set方法: tag在xib里填写

- (void)setClogcode:(NSString *)input{

    if (![input isEqualToString:clogcode]) {

        clogcode = [input copy ];

//        clogcodeLabel.text = clogcode;

        UILabel *label = (UILabel *)[self.contentView viewWithTag:1];

        label.text = clogcode;

    }

}

 

然后定义一个xib文件,拖入一个tableViewCell 点击这个cell 在Custom class里填写CustomCellVC,然后Identifier里填写哥字符串。此时不要连接输出口,切记,不知道为何,但是按书上写了就是有问题…… 

 

完成后就在列表里增加几行

列表

CustomCellVC *cell = [tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];

    if (cell == nil) {

//        cell =[[CustomCellVC alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellTableIdentifier]; //这个又不知道为啥又有问题

        //导入nib文件

        cell = [[[NSBundlemainBundle]loadNibNamed:@"CustomCellVC"owner:selfoptions:nil] objectAtIndex:0];

    }

//赋值

cell.clogcode =@“1”;

猜你喜欢

转载自andyzx168.iteye.com/blog/1864942