无法获取UITableViewCell中的值

时间:2011-04-04 07:35:43

标签: iphone objective-c cocoa-touch uitableview

我试图在UITableViewCell中获得价值,但无法获得!! 这是我的代码:

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

    static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

         tbcell.text = aBook.Name;
return cell;
}

当我打印这个值然后它在gdb中显示时,当我使用UITextField而不是cell时,它也会显示值...我不知道发生了什么!! 帮助

2 个答案:

答案 0 :(得分:2)

我甚至不确定你在问什么,但我会尝试,因为我马上看到一些奇怪的东西。

我会替换

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

你用一个带有0值的框架创建你的单元格,如果你是故意这样做的话,我可能会遗漏一些东西。

不推荐使用UITableViewCell的"text"属性,而是使用cell.textLabel.text

答案 1 :(得分:0)

为什么使用tbcell.text = aBook.Name;我认为cell.textLabel.text = aBook.Name;

相关问题