开发者

Determine the section of the tabbed UITextField

开发者 https://www.devze.com 2023-01-19 10:44 出处:网络
This is a tricky one: I have: - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

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;

    /开发者_StackOverflow/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?

0

精彩评论

暂无评论...
验证码 换一张
取 消