iphone - 在 UITableView 自定义单元格中获取值表单文本字段

标签 iphone objective-c ios5 xcode4.2

我已经创建了一个自定义的 UITableViewCell,单元格有多个文本字段,现在我想访问这些 UITextFields 中的字符串或数据。我知道我可以在 didSelectRowAtIndexPath 上获取单元格,但我需要在“保存”方法上获取文本。

最佳答案

假设您有四个带有标签 100 等到 104 的文本字段。 您将使用 Counter 显示您在 tableview 中有多少个单元格。

for (int i=0; iLessThanCounter; i++) {
            
     NSIndexPath *indexPath = [NSIndexPath indexPathForRow: i inSection: 0];
                
     UITableViewCell *cell = [mytableview cellForRowAtIndexPath:indexPath];
                
     for (UIView *view in  cell.contentView.subviews){                
                    
           if ([view isKindOfClass:[UITextField class]]){
                        
                  UITextField* txtField = (UITextField *)view;
                        
                  if (txtField.tag == 100) {
                         NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
                  }
                  if (txtField.tag == 101) {
                        NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
                  }
                  if (txtField.tag == 102) {
                        NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
                  }
                  if (txtField.tag == 103) {
                       NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);
                  }
                  if (txtField.tag == 104) {
                       NSLog(@"TextField.tag:%u and Data %@", txtField.tag, txtField.text);

                  } // End of isKindofClass 
              } // End of Cell Sub View
         }// Counter Loop
    }

关于iphone - 在 UITableView 自定义单元格中获取值表单文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11666588/

相关文章:

ios - 在 iOS-charts swift iOS 8 中设置 yAxis

iphone - 删除 subview

ios - 如何同时显示聊天 UI 的文本和按钮

ios - 如何使用xcode为iPad创建新的cocos3D项目?

iphone - iOS - 谁能建议我如何将 gmail 帐户集成到我的应用程序中并获取所有电子邮件的列表?

iphone - 我想在我的 iphone uiimageview 中显示来自 url 的视频的视频缩略图图像

iphone - UITableViewCell 滚动时的动画

ios - MMDrawerController触摸UISlider应用于iOS 7上的错误 View

ios - UIActivityIndi​​catorView 微调器未显示

iphone - 为什么 UITextview 没有像 UITextField 这样的占位符属性