简体   繁体   English

使用Xcode 7使用UITextfield自定义UITableViewCell

[英]Custom UITableViewCell with UITextfield using Xcode 7

I am using a custom UITableViewCell with a textfield. 我正在使用带有文本字段的自定义UITableViewCell I want to access each textfield's data when I press on the right navigation bar button (eg:Done,etc). 当我按下右侧导航栏按钮(例如:完成等)时,我想访问每个文本字段的数据。 I am using following code: 我正在使用以下代码:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 2;
}

#pragma mark - UITableViewDelegate

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

    CustomCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil] objectAtIndex:0];
    if (cell == nil) {

    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.valueTextField.delegate = self;
    switch (indexPath.row) {
        case 0:
            cell.itemImageView.image = [UIImage imageNamed:@"user.png"];
            cell.valueTextField.placeholder = @"UserName";
            break;
        case 1:
            cell.itemImageView.image = [UIImage imageNamed:@"mail.png"];
            cell.valueTextField.placeholder = @"Email";

        default:
            break;
    }

Try this 尝试这个

-(IBAction)rightNavigationButton:(id)sender
{

NSInteger rowNumber = [projectListTable numberOfRowsInSection:0];

    NSIndexPath *indexpath = [NSIndexPath indexPathForRow:[projectListTable numberOfRowsInSection:0] inSection:0];

    for(int i = 0; i < rowNumber; i++)
    {
        CustomCell *cell = [projectListTable cellForRowAtIndexPath:[NSIndexPath indexPathForRow:rowNumber inSection:0]];
        NSString *str =  cell.valueTextField.text;

//Do here what you want to do with textfield of each cell
    }
}

I solved the issue like this: 我解决了这样的问题:

 -(void)clickOnSend:(id)sender{

    NSInteger dynamicRows = [self.createUserTableView numberOfRowsInSection:0];
    for (int i=0; i<dynamicRows; i++) {
        NSIndexPath *indexPath = [NSIndexPath indexPathForRow:i inSection:0];
        UserProfileCell *cell = (UserProfileCell *)[self.createUserTableView cellForRowAtIndexPath:indexPath];
        DLog(@"cell textfield string :%@",cell.valueTextField.text);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 自定义UITableViewCell中的UITextField不可见 - UITextField in custom UITableViewCell not visible 在自定义UITableViewCell中访问UITextField - Accessing UITextField in a custom UITableViewCell 自定义UITableViewCell + UITextField问题 - Custom UITableViewCell + UITextField issues 使用Xcode中的自定义键盘来限制UITextfield中的文本 - Limit Text in UITextfield using a custom keyboard in Xcode 使用自定义UITableViewCell时,在编辑之前更改UITextField文本 - Change UITextField text right before editing when using custom UITableViewCell 自定义UITableViewCell中的UITextField-截断的自动更正 - UITextField in custom UITableViewCell - truncated autocorrection 在自定义UITableViewCell中关闭UITextField的问题 - Issue with dismissing UITextField in custom UITableViewCell 如何从自定义UItableViewCell获取UITextfield值。 如果UITableviewCell具有多个UITextFields而不使用标签属性 - How to get UITextfield value from custom UItableViewCell. If UITableviewCell have multiple UITextFields without using tag property UITableViewCell中的UITextField使用单元格的imageView - UITextField in UITableViewCell using imageView of cell 如何使用objective-C验证由UITableViewCell在自定义文件中创建的多个自定义UItextfield值 - How to validate a multiple custom UItextfield value which is created by UITableViewCell in custom file using objective-C
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM