Come inserire un UITextField all'interno di UITableViewCell (raggruppato)? Voglio che un utente sia in grado di modificarlo.Come inserire un UITextField all'interno di un UITableViewCell (raggruppato)?
5
A
risposta
5
Aggiungere il UITextField
come visualizzazione secondaria della contentView
del UITableViewCell:
[mycell.contentView addSubview:view];
2
propria applicazione demo UICatalog di Apple ha un esempio di collocare UITextFields in raggruppato UITableView Cells: http://developer.apple.com/iphone/library/samplecode/UICatalog/index.html
Controllare il contenuto della TextFieldController.m
Inoltre c'è un sacco di altri grandi codici per lavorare con gli oggetti UIKit.
1
Ecco come l'ho implementato nella mia applicazione, ma ovviamente dovrai cambiare alcune cose. Spero che questo ti aiuti.
- (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; }
Spero che sia d'aiuto.
Problemi correlati
- 1. UITextField in UITableViewCell Help
- 2. Imposta backgroundColor di UITableViewCell in UITableView raggruppato
- 3. Come selezionare un UITextField?
- 4. Come sottoclasse in modo affidabile UITableViewCell per UITableView raggruppato?
- 5. Come inserire i token di testo blu all'interno di UITextField?
- 6. Recupero di un frame UITableViewCell
- 7. Sottotitoli UITextField di UITableViewCell per diventare il primo soccorritore?
- 8. Come creare un UITextField su SpriteKit
- 9. Cambia lo sfondo di un UITableView raggruppato
- 10. Un UITextField con stato di primo soccorritore in UITableViewCell impedisce il riutilizzo della cella?
- 11. Inserimento di un titolo readonly in un UITextField
- 12. Modifica altezza di un UITableViewCell
- 13. Come ottengo le coordinate globali di un elemento svg raggruppato?
- 14. Mappare un insieme raggruppato utilizzando automapper
- 15. Ruota un UITableViewCell personalizzato
- 16. Come ottenere il indexPath di un UIButton in un UITableViewCell?
- 17. Come aggiungere UILongPressGestureRecognizer a un UITextField?
- 18. Come aggiungere una UIImage a UITableViewCell raggruppato in modo da arrotondare gli angoli?
- 19. Come sapere se un UITextField in iOS ha spazi vuoti
- 20. Un modo semplice per disabilitare un UITextField?
- 21. Immettere un UIImageView rightview ad un UITextField
- 22. Aggiunta di un metodo al mio uitextfield nella cella?
- 23. Come eseguire il loop su un dataframe Panda raggruppato?
- 24. Come creare un effetto ombra in uitableviewcell?
- 25. Ricarica solo un UITableViewCell su un UITableview
- 26. Centrare verticalmente un PortalPile attribuito di UITextField
- 27. combinazione di più CCSprites in un oggetto raggruppato in cocos2d
- 28. Disegna separatore verticale su UITableViewCell
- 29. Disabilitare la selezione di un singolo UITableViewCell
- 30. Disabilitazione dello scorrimento automatico di UITableView durante la modifica di UITextField all'interno di UITableViewCell