2015-01-14 27 views
-2

我在与自定义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]; 
} 

我之所以有它的设置,这是是这样我就可以“微管理”,在它的文字多一点。

+0

你能不能把你如何设置你为textLabel又是怎样MyCellObject模样的更多信息。我认为问题与您发布的代码无关。 –

+0

我在某处读到新的'-dequeue ...'方法已被更改,现在它永远不会返回'nil':如果没有单元可用于重用,它将分配一个。所以零检查变得没有必要。 –

+0

使用'MyCellObject * cell =(MyCellObject *)[tableView dequeueReusableCellWithIdentifier:@“cellid”]; “ –

回答

0

1)您没有设置小区称号。所以你不会在单元上看到任何文字。这里你使用了一个UITableViewCell类。因此,您需要在storyboard中为单元格添加标签,并在您的案例中设置了出口到UITableViewCell,这是MyCellObject类。然后,您将能够将文本设置为该标签。

2)可以只使用

MyCellObject *细胞=(MyCellObject *)[的tableView dequeueReusableCellWithIdentifier:@ “CELLID”];

尝试此..

- (的UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath {

MyCellObject *细胞=(MyCellObject *)[的tableView dequeueReusableCellWithIdentifier:@ “CELLID”];

cell.myCustomLabel.text = @ “您的文本”;

恢复单元;

}