尝试从iOS中UITableView的自定义单元格内的textField获取活动单元格的索引 [英] Trying to get index of active cell from textField inside custom cell of UITableView in iOS

查看:26
本文介绍了尝试从iOS中UITableView的自定义单元格内的textField获取活动单元格的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序中有一个 UITableView,其中我有自定义的 UITableViewCell,其中包含一个 UITextField.当我从该行中选择一个特定的文本字段时,我想要做的是获得该行的正确索引.不幸的是,我只有在实际单击行时才能获得该行的正确索引,而不是在我选择文本字段本身时.我正在实现 ,当我选择一个特定的 UITextField 时,我调用了该方法:

I have a UITableView in my application where I have custom UITableViewCell which contains a UITextField. What I would like to do is get the correct index of the row when I select a particular textfield from that row. Unfortunately, I am only able to get the correct index of the row if I actually click on the row, and not when I select the textfield itself. I am implementing the <UITextFieldDelegate>, and when I select a particular UITextField, I call the method:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {

    int rowTest = [_table indexPathForSelectedRow].row;
    int rowTest1 = [_cell.tireCodeField tag];

    NSLog(@"the current row is: %d", rowTest1);
    NSLog(@"and this row is: %d", rowTest);  

    return YES;

}

问题是我得到的行的值来自于方法:

The problem is that the value for the row that I am getting is from whenever the method:

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

   ...

}

get 被调用.就好像 UITextField 和它所在的表中的行之间存在断开.有没有办法让我选择一个特定的 textField,并获得

get's called. It is as if there is a disconnect between the UITextField and the row in the table it resides in. Is there a way for me to select a particular textField, and get the

有没有办法通过选择位于其中的 UITextField 而不是选择行本身来获取行的索引?

Is there a way for me to get the index of the row by selecting the UITextField that resides within it, instead of selecting the row itself?

提前感谢所有回复的人.

Thanks in advance to all who reply.

推荐答案

通常这样做的方式是给文本字段一个等于 indexPath.row 的标签,或者如果你有多个部分,一些数学组合部分和行(如 1000*indexPathSection + indexPath.row).

The way this is usually done, is to give the text field a tag equal to the indexPath.row, or if you have multiple sections, some mathematical combination of the section and row (like 1000*indexPathSection + indexPath.row).

这篇关于尝试从iOS中UITableView的自定义单元格内的textField获取活动单元格的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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