UITableViewCell不使用弃用方法initWithFrame:reuseIdentifier

Joo*_*ark 9 uitableview ios

我已经阅读了Loren关于为UITableViewCell绘制自己内容的文章.但是,他使用的是不推荐使用的方法:initWithFrame:reuseIdentifier:在UITableViewCell上已弃用.

如何在不使用的情况下让他的榜样上班initWithFrame:reuseIdentifier

Joo*_*ark 16

只需要替换initWithFrame:reuseIdentifier:以下内容.

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        // you might want to add the UIView to [self contentView] 
        // so that in edit's the cell's content will be automatically adjusted.
        ABTableViewCellView *myUIView = [[ABTableViewCellView alloc] initWithFrame:CGRectZero];

        myUIView.opaque = YES;
        contentViewForCell = myUIView;
        [self addSubview:myUIView];
        [myUIView release];
    }

    return self;
}
Run Code Online (Sandbox Code Playgroud)

此外,苹果有一个例子,洛伦指出,但他们使用 initWithStyle:reuseIdentifier:

http://developer.apple.com/iphone/library/samplecode/TableViewSuite/Introduction/Intro.html