我试图重新创建一个Xcode项目,但是我遇到了一个错误"'initWithFrame:reuseIdentifier‘is deprecated“。代码如下:
- (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;}我在line2上得到了if-语句开头的错误。这个函数显然不再推荐使用了,现在它是这个函数:
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
// Initialization code.
}
return self;}我真的不知道如何修改上面的函数并将其放入较新的函数中!
Thx
凯文
发布于 2011-07-10 20:23:33
新的初始化器使用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;
}您现在拥有:
- (id)initWithStyle:(UITableViewCellStyle)style
reuseIdentifier:(NSString *)reuseIdentifier {
if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
// all your stuff
}
return self;
}https://stackoverflow.com/questions/6640891
复制相似问题