代码之家  ›  专栏  ›  技术社区  ›  meersmans

确定选项卡UITEXT字段的部分

  •  1
  • meersmans  · 技术社区  · 14 年前

    这是一个棘手的问题:

    我有:

    - (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]; 我不能用这个。标记属性,因为我添加了行。 我怎样才能得到部门的电话号码?

    0 回复  |  直到 10 年前