【发布时间】:2014-07-11 17:56:54
【问题描述】:
我的自定义表格视图单元格的代码如下所示。我在每个自定义单元格中有 5 个标签,它们可以通过它们的标签而不是它们的标签来区分。 (每个标签都有不同的标签)。不使用标签 ID。因此,如果我要通过下面显示的方法从单元格中的标签中提取 NSString,我如何知道正在拉哪个字符串? 我不确定这段代码是否可以工作
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NoViewController *noViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"NoViewController"];
NSString *label1 = [_nodes objectAtIndex:indexPath.row];
NSString *label2 = [_nodes objectAtIndex:2];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
Node *node = [self.nodes objectAtIndex:indexPath.row];
static NSString *CellIdentifier = @"NodeCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:
CellIdentifier forIndexPath:indexPath];
UILabel *label;
label = (UILabel *)[cell viewWithTag:1];
label.text = node.nodeid;
label = (UILabel *)[cell viewWithTag:2];
label.text = [NSString stringWithFormat:@" %.0f"];
label = (UILabel *)[cell viewWithTag:3];
label.text = [NSString stringWithFormat:@" %.0f"];
label = (UILabel *)[cell viewWithTag:4];
label.text = [NSString stringWithFormat:@" %.0f"];
label = (UILabel *)[cell viewWithTag:5];
label.text = [NSString stringWithFormat:@" %.0f"];
label = (UILabel *)[cell viewWithTag:6];
label.text = [NSString stringWithFormat:@" %.0f"];
label = (UILabel *)[cell viewWithTag:7];
label.text = [NSString stringWithFormat:@" %.0f"];
return cell;
}
AppDelegate.m
RKManagedObjectMapping *nodeMapping = [RKManagedObjectMapping mappingForClass:[Node class] inManagedObjectStore:objectStore];
【问题讨论】:
-
你的问题很不清楚。您发布的代码没有从任何单元格的任何标签中获取文本。
_nodes是什么(除了数组)? -
我认为这就是我的问题所在。 _nodes 是一个包含 6 个对象的数组,每个对象包含 5 个字符串。我对如何从自定义单元格中提取字符串的值感到困惑
-
如何在
cellForRowAtIndexPath方法中设置每个单元格?您从_nodes获得数据,对吗?在didSelectRowAtIndexPath中做同样的事情。无需访问单元格或标签。只需从节点中获取字符串,就像设置单元格一样。 -
单元格中的每个标签都被来自服务器的数据填充。这就是为什么我需要在填满单元格标签后访问它们。单击后,我需要将这些字符串从选定的表格单元格传递到 detailviewcontroller。
-
@AkhilYeleswarapu 您想将所选节点传递给详细视图是您想要实现的目标吗?
标签: ios objective-c uitableview tableview