我在与自定义UITableViewCell创建我的UITableViewCell麻烦:initWithFrame:方法reuseIdentifier已被弃用。请留在我身边,我已经看过关于此问题的其他问题,但找不到它们有帮助。所以这是我的功能。的UITableViewCell:initWithFrame:方法reuseIdentifier弃用
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCellObject *cell = (MyCellObject *)[tableView_ dequeueReusableCellWithIdentifier:@"cellid"];
if (cell == nil) {
cell = [[[ChatCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"cellid"] autorelease];
}
return cell;
}
当我从其他的问题看,我想:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
MyCellObject *cell = (MyCellObject *)[tableView_ dequeueReusableCellWithIdentifier:@"cellid"];
if (cell == nil) {
cell = [[[MyCellObject alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cellid"] autorelease];
}
return cell;
}
但我的细胞不会显示其文本,然后。我可以点击单元格行,它变成了选择,但没有可见的文本。因为我的手机文本在我的MyCellObject
而不是cell.textLabel.text
处理,我需要一个框架(initWithFrame
)给init细胞,但我也需要有一个标识符(reuseIdentifier
),以初始化它。
谢谢!
编辑:我不认为MyCellObject
作为一切工作,已被否决上述功能之前。下面是MyCellObject
一部分,它是从UITableViewCell
得出:
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier];
if (self == nil) {
return nil;
}
tagLabel = [[UILabel alloc] initWithFrame:CGRectZero];
tagLabel.backgroundColor = [UIColor clearColor];
tagLabel.font = [UIFont systemFontOfSize:14];
tagLabel.lineBreakMode = UILineBreakModeWordWrap;
tagLabel.opaque = YES;
[self addSubview:tagLabel];
}
我之所以有它的设置,这是是这样我就可以“微管理”,在它的文字多一点。
你能不能把你如何设置你为textLabel又是怎样MyCellObject模样的更多信息。我认为问题与您发布的代码无关。 –
我在某处读到新的'-dequeue ...'方法已被更改,现在它永远不会返回'nil':如果没有单元可用于重用,它将分配一个。所以零检查变得没有必要。 –
使用'MyCellObject * cell =(MyCellObject *)[tableView dequeueReusableCellWithIdentifier:@“cellid”]; “ –