0

我有多个部分UITableView(大约 12 个部分),每个部分都有一行或多行。UITextField当我选择一行时,如何在我的 Delegate 方法中获取节号?

4

6 回答 6

3

如果您在单元格中添加了文本字段,例如

[cell.contentview addSubview:yourtextfield];

然后在文本字段代表上

UITableViewCell *cell = (UITableViewCell *)[[textField superview] superview];
NSIndexPath *indexPath = [yourTableView indexPathForCell:cell];

NSLog(@"your Indexpath %d",indexPath.section);
于 2012-09-14T10:12:55.750 回答
1

当用户选择行时,您的代码需要处理对

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
    {
        ** your code here**
    }

indexPath传递到此方法中的同时包含节和行。了解如何使用它的最佳方法是查看 NSIndexPath 的文档,但我相信类似

indexPath.section 

是你需要的。

于 2012-09-14T10:14:57.847 回答
1

试试这个:-

-(void) textFieldDidBeginEditing:(UITextField *)textField {


    UITableViewCell *clickedCell = (UITableViewCell *)[textField superview];
    int section = [topicTable  indexPathForCell:clickedCell].section;
    NSLog(@"section %d", section);

}
于 2012-09-14T10:25:32.483 回答
0

它显示标签值,文本字段值,试试这个代码(使用标签)

- (void)textFieldDidEndEditing:(UITextField *)textField {

   NSLog(@"%d : %@", textField.tag,textField.text);
    [textField resignFirstResponder];


}
于 2012-09-14T10:29:23.463 回答
0
UITableViewCell *cell = (UITableViewCell *)[[textField superview]superview];
NSIndexPath *indexPath = [yourTableView indexPathForCell:cell];

NSLog(@"your Indexpath %d",indexPath.section);

但是我建议你将来在使用 uitableviewcell 执行标签操作时创建一个 customcell

于 2012-09-14T10:42:49.023 回答
-1

如果您在界面构建器中手动创建了表格视图,即使用静态单元格,那么您可以在每个 UITextField 中使用标签,然后在委托方法中检查它。

对于 12 个部分,您可以将标签编号为 ,例如 1203 是第 12 部分的第 3 行,或 600 是第 6 部分的第 0 行。

于 2012-09-14T10:13:37.133 回答