iphone - 3.0之后如何使用initWithStyle制作自定义TableViewCell

标签 iphone iphone-sdk-3.0 uitableview initwithstyle

我正在尝试使用 initWithStyle 自定义 TableViewCell,因为它说 initWithFrame 在 3.0 后已弃用。之前 initWithFrame 一切正常。

有可用的教程或示例代码吗?谢谢。

最佳答案

我对 UITableViewCell 进行了子类化,然后重写了 initWithStyle 方法。

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;

        // Initialization code
        msgText = [[UILabel alloc] init];
        [self.contentView addSubview:msgText];  
    }
    return self;
}

msgText 是该类的 UILabel 属性,我在其他地方设置了标签的文本属性。您可以将任何您喜欢的 View 添加到 self.contentView 中。当我添加文本和/或图像等内容时,我还会设置每个 subview 的框架。

关于iphone - 3.0之后如何使用initWithStyle制作自定义TableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1754036/

相关文章:

iphone - 部分左侧的 UITableView 标题(如 Spotlight)

iphone - 如何制作一个可以覆盖导航栏的UIView?

iphone - UILabel 和 TextView 的 HTML 字符串内容

ios - UIPageViewController EdgeInset 问题中的 UITableView

ios - 自定义应用程序中的 UITableview 部分

ios - UITableViewController 嵌入到另一个 UIView 的容器中时不显示内容

iphone - 重复的方法名称 - Objective-c

iphone - iOS:选择选项第一次返回 null,而不是第二次

iphone - 这些位掩码实际上是如何工作的?

ios - 如何为我的 iOS Cocos2d 游戏保存游戏数据?