开发者

'initWithFrame:reuseIdentifier' is deprecated

I was trying to recreate a Xcode project but I came across an error "'initWithFrame:reuseIdentifier' is deprecated". Here is the code:

- (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 a开发者_运维技巧ddSubview: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;}

I am getting the error on line2 with the start of the if-statement. This function is clearly not adviceable to use anymore and it now is this function:

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

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

I don't really know how I can modify the above function and put it in the newer function! Could some1 help me on this matter please?

Thx

Kevin


The new initializer is using a UITableViewCellStryle instead of specifying the frame CGRect for the cell and you were just giving the frame to the superclass in [super initWithFrame:frame reuseIdentifier:reuseIdentifier]. So, there should be not problem to put all the same code in the new version, without the if statement.

You had :

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

You now have :

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜