在didselect行我的第一行returnig标签文本而不是我的自定义标签文本

时间:2014-12-17 08:10:10

标签: uitableview uilabel didselectrowatindexpath

这里我有一个表视图,我正在添加自定义标签,存储一些 来自数组的测验ID 其中cell.textlabel.text存储数组

中的测验名称

问题: 当我在didselectRowAtIndexPath中选择第一行时 它返回cell.textlabel.tex,但对于第二行,它返回正确的值 测验ID

这是代码

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"CellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];

}
cell.textLabel.text = [quizname objectAtIndex:indexPath.row];

UILabel *lbl = [[UILabel alloc]init];
lbl.tag=indexPath.row;
[cell addSubview:lbl];
lbl.text = [quizIds objectAtIndex:indexPath.row];

return cell;
}

in selectrow

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UILabel *label = (UILabel *) [cell viewWithTag:indexPath.row];
NSString *qid =label.text;
NSLog(@"%@",qid);

}

我得到的quid等于第一行的cell.texlabel.text但是其他行没有 他们完全得到了测验ID

对我来说最有价值的任何帮助

1 个答案:

答案 0 :(得分:0)

尝试使用customTableViewCell&在customCell中添加标签。在cellForRowAtIndexPath中添加UILabel不是一个好方法。

相关问题