У меня есть один текстовый фильтр в разделе выделения ячеек, и после этого раздела я пытаюсь предоставить текстовое поле различным аргументам. Работает нормально, нет проблем до сих пор, проблема заключается в том, как обрабатывать, какой textField возвращается в методе делегата.Handeling single uitextfield в UITableView
Мой более ранний подход состоял в том, чтобы просто выделить различные текстовые поля для разных пользовательских ввода, простые, но создает сбои пользовательского интерфейса, когда есть много текстовых полей, поэтому нужно избегать его.
для лучшего понимания здесь приведен пример кода для метода таблицы делегата cellAtIndexRow
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellTableIdentifier = @"CellTableIdentifier";
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellTableIdentifier];
if (cell == nil) {
// Create a new cell. CGRectZero allows the cell to determine the appropriate size.
CGRect cellFrame = CGRectMake(0,0,300,65);
cell = [[[UITableViewCell alloc] initWithFrame:cellFrame reuseIdentifier:CellTableIdentifier] autorelease];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(8,4,284,25)];
textField.delegate = self;
textField.returnKeyType = UIReturnKeyDone;
textField.tag = kTagAddContactTextField;
textField.backgroundColor = [UIColor orangeColor];
[cell.contentView addSubview:textField];
[textField release];
}
UITextField *textField = (UITextField*)[cell.contentView viewWithTag:kTagAddContactTextField];
switch (indexPath.row) {
case 0:
[textField setPlaceholder:@"First Name"];
break;
case 1:
[textField setPlaceholder:@"Last Name"];
break;
case 2:
[textField setPlaceholder:@"Email"];
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.autocapitalizationType = UITextAutocapitalizationTypeNone;
textField.keyboardType = UIKeyboardTypeEmailAddress;
break;
}
//cell.textLabel.text = @"Test";
return cell;
}
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
//here is the place where I wann to handle various text fields and store there values.
return YES;
}
Обратите внимание, что вам нужно установить autocorrectionType/autocapitalizationType/keyboardType в строках 0 и 1, в случае, если ячейка из строки 2 повторно используется. –