我正在尝试获取 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/