如何从UITableview的选定行获取cell.label.text值? [英] How to get the cell.label.text values from a selected row of UITableview?

查看:166
本文介绍了如何从UITableview的选定行获取cell.label.text值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是iOS应用程序开发的新手,我需要有关UItableview的帮助。因为我用json数据填充表视图。我也使用Customized Tableviewcell。
我没有在lbluid上获得所选单元格的huid值。 lbluid根据滚动显示huid的值,因为我将向上滚动它将显示UITableview最上面可见单元格的huid值,如果我向下滚动它将显示last的huid值从下来的可见细胞。

I am new in iOS application Development and i need help on UItableview. As i am populating the table-view with json data.I am also Using Customized Tableviewcell also. I am not getting the "huid" value of selected cell on "lbluid". The "lbluid" is showing value of "huid" according to scroll as i will scroll up it will show the "huid" value of upper most visible cell of the UITableview and if i scroll down it will show the "huid" value of last visible cell from down.

- (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

推荐答案

您可能需要实施该方法:

You may have to implement the method:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

每次选择一行时调用,并在该方法内调用:

which is called each time a row is selected, and inside that method:

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

方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

被称为表视图正在加载要显示的单元格,这就是为什么 lbluid.text 仅在滚动表视图时才会更改。

is called the the table view is loading it's cells to be displayed, which is why you lbluid.text is only changing when the table view is scrolled.

这篇关于如何从UITableview的选定行获取cell.label.text值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆