ios - UITableViewCell 不使用不推荐使用的方法 initWithFrame :reuseIdentifier

标签 ios uitableview

我已阅读 Loren's article关于为 UITableViewCell 绘制您自己的内容。但是,他使用的是一种已弃用的方法:initWithFrame:reuseIdentifier: is deprecated on UITableViewCell。

如何在不使用 initWithFrame:reuseIdentifier 的情况下让他的示例工作?

最佳答案

只需将 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;
}

此外,正如 Loren 指出的那样,苹果有一个例子,但他们使用 initWithStyle:reuseIdentifier:

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

关于ios - UITableViewCell 不使用不推荐使用的方法 initWithFrame :reuseIdentifier,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2815121/

相关文章:

Ios 通过浏览器或其他带有 url 的应用程序上传和下载 .app 文件

ios - BOOL 方法有问题

iOS - 处理大图像

ios - didSelectRow 未很好地注册单元格触摸

ios - CoreData 对象未在屏幕之间保存

ios - 获取表的索引路径

ios - 需要 MAC 笔记本电脑配置才能开始处理 Xcode、iPhone 应用程序并推送到 AppStore

ios - Xcode 8 App Archive 验证失败并出现错误

iphone - boolean 值没有在正确的时刻设置

ios - 如何向原型(prototype)单元格添加两个以上的标签?