'initWithFrame:reuseIdentifier'已弃用

Kev*_*vin 5 cocoa-touch ios

我试图重新创建一个Xcode项目,但我遇到了一个错误"'initWithFrame:reuseIdentifier'已被弃用".这是代码:

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
    UIView *myContentView = self.contentView;

    self.todoPriorityImageView = [[UIImageView alloc] initWithImage:priority1Image];
    [myContentView addSubview:self.todoPriorityImageView];
    [self.todoPriorityImageView release];

    self.todoTextLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] 
                                          selectedColor:[UIColor whiteColor] fontSize:14.0 bold:YES]; 
    self.todoTextLabel.textAlignment = UITextAlignmentLeft; // default
    [myContentView addSubview:self.todoTextLabel];
    [self.todoTextLabel release];

    self.todoPriorityLabel = [self newLabelWithPrimaryColor:[UIColor blackColor] 
                                              selectedColor:[UIColor whiteColor] fontSize:10.0 bold:YES];
    self.todoPriorityLabel.textAlignment = UITextAlignmentRight;
    [myContentView addSubview:self.todoPriorityLabel];
    [self.todoPriorityLabel release];

    // Position the todoPriorityImageView above all of the other views so
    // it's not obscured. It's a transparent image, so any views
    // that overlap it will still be visible.
    [myContentView bringSubviewToFront:self.todoPriorityImageView];
}return self;}
Run Code Online (Sandbox Code Playgroud)

我在if2语句的开头遇到了line2上的错误.这个功能显然不再适合使用了,它现在就是这个功能:

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

self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
    // Initialization code.
}
return self;}
Run Code Online (Sandbox Code Playgroud)

我真的不知道如何修改上面的功能并把它放在更新的功能中!some1能帮我解决这个问题吗?

谢谢

凯文

小智 5

新的初始化程序使用UITableViewCellStryle而不是指定CGRect单元格的框架,而您只是将框架提供给超类[super initWithFrame:frame reuseIdentifier:reuseIdentifier].因此,如果没有if语句,将所有相同的代码放在新版本中应该没有问题.

你有过 :

- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {
        // all your stuff
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)

你现在有:

- (id)initWithStyle:(UITableViewCellStyle)style
    reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        // all your stuff
    }
    return self;
}
Run Code Online (Sandbox Code Playgroud)