代码自定义UITableViewCell

来源:互联网 发布:mysql分页加排序语句 编辑:程序博客网 时间:2024/06/08 06:52
在自定义UITableViewCell时,cell中布局一般写在

-(id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier方法中,运行时时常出现错误,错误信息如下:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Requesting the window of a view (<merchantCell: 0x7f8e724597f0; baseClass = UITableViewCell; frame = (0 0; 0 0); transform = [0, 0, 0, 0, 0, 0]; alpha = 0; opaque = NO; autoresize = W; layer = (null)>) with a nil layer. This view probably hasn't received initWithFrame: or initWithCoder:.'

错误原因是因为initWithStyle方法中没调用父类的initWithStyle方法,即应该如下写:

if(self = [super initWithStyle:stylereuseIdentifier:reuseIdentifier])

{

//填写cell中布局代码

}

0 0
原创粉丝点击