Uitableview 在DID中,选择行我的第一行返回标签文本,而不是我的自定义标签文本

Uitableview 在DID中,选择行我的第一行返回标签文本,而不是我的自定义标签文本,uitableview,uilabel,didselectrowatindexpath,Uitableview,Uilabel,Didselectrowatindexpath,这里我有一个表视图,我在其中添加了自定义标签,其中存储了一些 来自阵列的测试ID 其中cell.textlab.text存储数组中的测验名称 问题: 当我在didselectRowAtIndexPath中选择第一行时 它返回cell.textlab.tex,但对于第二行,它返回的是正确的值,即 测验ID 这是代码 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *

这里我有一个表视图,我在其中添加了自定义标签,其中存储了一些 来自阵列的测试ID 其中cell.textlab.text存储数组中的测验名称

问题: 当我在didselectRowAtIndexPath中选择第一行时 它返回cell.textlab.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;
}
在第二行

- (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,但不等于其他行的cell.texlabel.text 他们得到了完美的测验ID


任何对我最有价值的帮助

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

回答很好,但CellForRowatineXpath中的错误是什么?使用断点并签入CellForRowatineXpath。添加如下条件。如果indexPath==0{cell.textLabel.text=[yourArray objectAtIndex:0];}否则{cell.textLabel.text=[yourArray objectAtIndex:1]}。并在didSelectRowAtIndexPath中使用断点&检查它是否抛出正确的值。在选择行后您是否遇到问题?