views:

15

answers:

0

This is a tricky one:

I have:

- (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];


}

and:

- (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];
    }
...

But i need the section of the cell where the textfield is in... So not: NSIndexPath *indexPath = [NSIndexPath indexPathForRow:textField.tag inSection:0]; I cant use the .tag property anymore because i added the row to that. How can i get the number of the section?