如何从UITableview的选定行获取cell.label.text值?

如何从UITableview的选定行获取cell.label.text值?,uitableview,ios6,Uitableview,Ios6,我是iOS应用程序开发新手,需要有关UItableview的帮助。当我用json数据填充表视图时,我还使用定制的Tableviewcell。 我没有在“lbluid”上获取所选单元格的“huid”值。“lbluid”根据滚动显示“huid”的值,因为我将向上滚动,它将显示UITableview最上面可见单元格的“huid”值,如果我向下滚动,它将显示从下到下最后可见单元格的“huid”值 - (UITableViewCell *)tableView:(UITableView *)tableVie

我是iOS应用程序开发新手,需要有关UItableview的帮助。当我用json数据填充表视图时,我还使用定制的Tableviewcell。 我没有在“lbluid”上获取所选单元格的“huid”值。“lbluid”根据滚动显示“huid”的值,因为我将向上滚动,它将显示UITableview最上面可见单元格的“huid”值,如果我向下滚动,它将显示从下到下最后可见单元格的“huid”值

- (UITableViewCell *)tableView:(UITableView *)tableView
     cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *simpleTableIdentifier = @"SimpleTableCell";
    SimpleTableCell *cell = (SimpleTableCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)  {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];;
    }

    NSUInteger row = [indexPath row];

    cell.lbl4.text = [hudid objectAtIndex:row];
    lbluid.text=cell.lbl4.text;
    return cell;
}

Simpletablecell
是定制的
UITableViewCell

您可能需要实现以下方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
每次选择一行时都会调用,并且在该方法中:

Simpletablecell *cell = (Simpletablecell *)[tableView cellForRowAtIndexPath:indexpath];
lbluid.text = cell.lbl4.text;
方法:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
被称为“表格视图正在加载要显示的单元格”,这就是为什么
lbluid。文本只有在表格视图滚动时才会更改。

在Swift中

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

       let cell = tableView.cellForRow(at: indexPath) as! NotesCell!
        let value = cell?.lblDetail.text
    }

非常感谢您的帮助@Andrew Tetlaw它对我有效,即使我在您回答之前就得到了这个解决方案,但它给出了警告“不兼容的指针类型初始化'Simpletablecell*”……请确保类名正确:
Simpletablecell
,并且它是
UITableViewCell
的子类。另外,该错误消息的其余部分是什么?它应该有一些额外有用的信息。像这样对单元格进行类型转换是否有任何风险?