确定选项卡式UITextField的部分

时间:2010-10-12 08:58:51

标签: iphone uitableview tags uitextfield

这是一个棘手的问题:

我有:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
...
//Textfield:
            UITextField *theTextField = [[UITextField alloc] initWithFrame:CGRectMake(200, 10,self.tableView.frame.size.width - 250, 30)];
            theTextField.adjustsFontSizeToFitWidth = YES;
            theTextField.textColor = [UIColor blackColor];

            theTextField.placeholder = [NSString stringWithFormat:@"%@ (mm)",[dictionarySub objectForKey:@"Title"]];
            theTextField.keyboardType = UIKeyboardTypeDefault;
            theTextField.returnKeyType = UIReturnKeyDone;

            theTextField.backgroundColor = [UIColor whiteColor];
            theTextField.autocorrectionType = UITextAutocorrectionTypeNo;
            theTextField.autocapitalizationType = UITextAutocapitalizationTypeNone; // no auto capitalization support
            theTextField.textAlignment = UITextAlignmentLeft;
            theTextField.tag = indexPath.row;
            theTextField.delegate = self;
            theTextField.clearButtonMode = UITextFieldViewModeWhileEditing; // no clear 'x' button to the right
            [theTextField setEnabled: YES];

            //Maak cell unselectable
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            [cell addSubview:theTextField];


}

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

    //Textfield ophalen
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0];
    UITableViewCell *selectedCell = [self.tableView cellForRowAtIndexPath:indexPath];
    editingCell = selectedCell;

    //Dictionary ophalen
    NSArray *subViewItemsToUse;
    subViewItemsToUse = [self getSubViewItemsToUse:indexPath];
    NSDictionary *dictionarySub = [subViewItemsToUse objectAtIndex:textField.tag];

    //Regex ophalen
     NSString *regularExpressionString  = [dictionarySub objectForKey:@"Regex"];

    //predicate opstellen
    NSPredicate *regExPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regularExpressionString];
    BOOL myStringMatchesRegEx = [regExPredicate evaluateWithObject:textField.text];

    if(!myStringMatchesRegEx && [textField.text length] > 0 && [regularExpressionString length] > 0)
    {
        textField.backgroundColor = [UIColor redColor];
        editingCell.backgroundColor = [UIColor redColor];
    }
    else 
    {
        editingCell.backgroundColor = [UIColor whiteColor];
        textField.backgroundColor = [UIColor whiteColor];
    }
...

但是我需要文本字段所在的单元格区域... 所以不是:  NSIndexPath *indexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0]; 我不能再使用.tag属性,因为我添加了行。 我如何获得该部分的编号?

0 个答案:

没有答案