iphone - 无法获取 UITableViewCell 中的值

标签 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 时它也显示值..我不知道发生了什么! ! 帮助。

最佳答案

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

我会替换

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

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

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

还有 "text" UITableViewCell 的属性已弃用,请改用 cell.textLabel.text

关于iphone - 无法获取 UITableViewCell 中的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5535734/

相关文章:

iphone - 子字符串在 NSString 中的位置

iphone - 自定义 CorePlot gridLineStyle

objective-c - 完成 block 不执行

ios - 将 "Clear"按钮添加到 iPhone UITextField

ios - 按主页时退出应用程序

iphone - 如何在不使用本地通知的情况下创建一个可以在一周内随机设置几天的自定义警报?

iphone - iPhone 旋转时按钮消失

iphone - 通过 segue 传输 View Controller 后隐藏单元格

iPhone CorePlot : Candle Stick , 放大和缩小时如何设置每根棍子之间的距离?

objective-c - 循环提示是或否?