Wie setze ich ein UITextField in eine UITableViewCell (gruppiert)? Ich möchte, dass ein Benutzer sie bearbeiten kann.Wie setze ich ein UITextField in eine UITableViewCell (gruppiert)?
5
A
Antwort
5
die UITextField
als Subview der contentView
des UITableViewCell hinzufügen:
[mycell.contentView addSubview:view];
2
Apples eigene UICatalog Demo-Anwendung hat ein Beispiel für UITextFields in gruppierten UITableView Zellen platzieren: http://developer.apple.com/iphone/library/samplecode/UICatalog/index.html
Überprüfen Sie den Inhalt von TextFieldController.m
Außerdem gibt es noch viele andere großartige Codes für die Arbeit mit UIKit Objects.
1
Dies ist, wie ich es in meine Anwendung implementiert habe, aber Sie müssen natürlich ein paar Dinge ändern. Hoffe das hilft.
- (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; }
Ich hoffe, es hilft.
Verwandte Themen
- 1. UITextField in UITableViewCell
- 2. UITextField in UITableViewCell Hilfe
- 3. Wie wähle ich ein UITextField?
- 4. Wie setze ich einen Gradienten UITableViewCell Hintergrund?
- 5. Wie setze ich eine globale Platzhalterfarbe für ein UITextField für die gesamte App in swift?
- 6. UITextField in UITableViewCell - Hinzufügen neuer Zellen
- 7. UITextField in UITableViewCell werdenFirstResponder nach dem Einfügen
- 8. erhalten Daten von UITextField in UITableViewCell
- 9. Setze die Cursorposition in einem UITextField (Monotouch)
- 10. Wie setze ich UITableViewCell Hintergrundbild mit verschiedenen Höhen?
- 11. Wie setze ich UITableViewCell Höhe abhängig von der Bildschirmgröße
- 12. Wie bekomme ich ein UITableViewCell von einem seiner Subviews
- 13. Wie setze ich Variablenwerte in eine Textzeichenfolge in MATLAB ein?
- 14. Edit NSManagedObject in einem UITextField in einem UITableViewCell
- 15. Wie setze ich Zufallszahlen ein?
- 16. Wie erstelle ich ein transparentes UITextField?
- 17. Wie setze ich ein Glas in mvnrepository.com?
- 18. Wie setze ich $ und setze ein Update MongoDB ein?
- 19. Wie schreibe ich eine benutzerdefinierte UItextField Klasse
- 20. Wie setze ich ein Passwort in eine SQLite-Datenbank?
- 21. Wie fixiere ich ein UITextField unter UITableView?
- 22. textFieldShouldBeginEditing: Mehrere Male für UITextField in UITableViewCell aufgerufen werden
- 23. Wie setze ich ein Tabellenpräfix in Yii
- 24. Wie setze ich ein Fenster in Powershell?
- 25. Wie setze ich ein Hintergrundbild in Java?
- 26. Wie setze ich viewController in ein UIScrollView
- 27. Wie setze ich ein Bind in C#
- 28. Wie setze ich Körper in ein Versprechen?
- 29. Wie setze ich eine Umgebungsvariable in Perl?
- 30. Highcharts: Wie setze ich DataGrouping?