Как установить UITextField внутри UITableViewCell (сгруппировано)? Я хочу, чтобы пользователь мог его редактировать.Как установить UITextField внутри UITableViewCell (сгруппировано)?
5
A
ответ
5
Добавьте UITextField
как подвид из contentView
в UITableViewCell в:
[mycell.contentView addSubview:view];
2
компании Apple собственного UICatalog демонстрационное приложение имеет пример размещения UITextFields в Сгруппированном UITableView клеток: http://developer.apple.com/iphone/library/samplecode/UICatalog/index.html
Проверьте содержимое TextFieldController.m
Плюс есть много отличного кода для работы с объектами UIKit.
1
Вот как я внедрил его в свое приложение, однако вам, очевидно, нужно будет изменить несколько вещей. Надеюсь это поможет.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
// Configure the cell.
//adding all the UITextField's to the UITableViewCell is a pain in the ass. Pretty sure this is correct though.
if ([indexPath section] == 0) {
tUser = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
tUser.adjustsFontSizeToFitWidth = YES;
tUser.textColor = [UIColor blackColor];
tPass = [[UITextField alloc] initWithFrame:CGRectMake(110, 10, 185, 30)];
tPass.adjustsFontSizeToFitWidth = YES;
tPass.textColor = [UIColor blackColor];
if ([indexPath section] == 0) {
if ([indexPath row] == 0) {
tUser.placeholder = @"@JohnAppleseed";
tUser.keyboardType = UIKeyboardTypeEmailAddress;
tUser.returnKeyType = UIReturnKeyNext;
}
if ([indexPath row] == 1) {
tPass.placeholder = @"Required";
tPass.keyboardType = UIKeyboardTypeDefault;
tPass.returnKeyType = UIReturnKeyDone;
tPass.secureTextEntry = YES;
}
}
tUser.backgroundColor = [UIColor whiteColor];
tUser.autocorrectionType = UITextAutocorrectionTypeNo;
tUser.autocapitalizationType = UITextAutocapitalizationTypeNone;
tUser.textAlignment = UITextAlignmentLeft;
tPass.backgroundColor = [UIColor whiteColor];
tPass.autocorrectionType = UITextAutocorrectionTypeNo;
tPass.autocapitalizationType = UITextAutocapitalizationTypeNone;
tPass.textAlignment = UITextAlignmentLeft;
tUser.clearButtonMode = UITextFieldViewModeNever;
tPass.clearButtonMode = UITextFieldViewModeNever;
[tUser setEnabled:YES];
[tPass setEnabled:YES];
//[tUser release];
//[tPass release];
}
if ([indexPath section] == 0) { // Email & Password Section
if ([indexPath row] == 0) { // Email
cell.textLabel.text = @"Username";
[cell addSubview:tUser];
[tUser setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_name_preference"]];
}
else {
cell.textLabel.text = @"Password";
[cell addSubview:tPass];
[tPass setText:[[NSUserDefaults standardUserDefaults] objectForKey:@"twitter_pass_preference"]];
}
}
return cell; }
Надеюсь, это поможет.
Смежные вопросы
- 1. UITextField внутри UITableViewCell
- 2. UITableViewCell (сгруппировано) подвью перед телом
- 3. Обратитесь к определенному UITextField внутри определенного UITableViewCell
- 4. UITextField текст внутри UITableViewCell исчезает на свитке
- 5. UITextField внутри UITableViewCell для удаления проблемы
- 6. UITextField внутри UITableViewCell не станет первым ответчиком
- 7. Редактировать NSManagedObject в UITextField внутри UITableViewCell
- 8. Удалить жестов Tap из UITextField внутри UITableViewCell
- 9. Сохраните UITextField внутри UITableViewCell до NSMutableArray
- 10. UITextField внутри UITableViewCell - метод предотвращения сброса текста
- 11. UITextField внутри UITableViewCell: getFirstResponder in didSelectRowAtIndexPath
- 12. Символы, не очищенные в UITextField внутри UITableViewCell
- 13. UITextField внутри UITableViewCell стирается при прокрутке
- 14. UITextField в UITableViewCell Help
- 15. Autoresize UITextField в UITableViewCell
- 16. Уникальность UITextField в UITableViewCell
- 17. Где установить UIRectCorner внутри UITableViewCell
- 18. UITextField в UITableViewCell
- 19. Ограничения UITextfield в UITableViewCell
- 20. Как получить индекс UITableViewCell из UITextField?
- 21. Передайте текст UItextfield из UItableViewcell.
- 22. UITextField в UITableViewCell
- 23. Добавление UITextField в UITableViewCell
- 24. UITableViewCell с UITextField в ячейке
- 25. UITextField внутри ячейки UITableView
- 26. Как правильно добавить UITextField в UITableViewCell
- 27. Пограничный цвет представления UITextField в UITableViewCell
- 28. Как установить высоту UITableViewCell
- 29. Отключение автоматической прокрутки UITableView при редактировании UITextField внутри UITableViewCell
- 30. Нажмите UITableViewCell, чтобы установить фокус в UITextField в iPad