Làm thế nào để đặt một UITextField bên trong của một UITableViewCell (nhóm)? Tôi muốn người dùng có thể chỉnh sửa nó.Làm thế nào để đặt một UITextField bên trong của một UITableViewCell (nhóm)?
5
A
Trả lời
5
Thêm UITextField
như một subview của contentView
của UITableViewCell:
[mycell.contentView addSubview:view];
2
riêng ứng dụng demo UICatalog của Apple có một ví dụ về cách đặt UITextFields trong nhóm UITableView Cells: http://developer.apple.com/iphone/library/samplecode/UICatalog/index.html
Kiểm tra các nội dung của TextFieldController.m
Plus có rất nhiều mã tuyệt vời khác ở đó để làm việc với các đối tượng UIKit.
1
Đây là cách tôi đã triển khai nó vào ứng dụng của mình, tuy nhiên bạn rõ ràng sẽ cần phải thay đổi một vài điều. Hi vọng điêu nay co ich.
- (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; }
Hy vọng điều đó sẽ hữu ích.
Các vấn đề liên quan
- 1. Đặt backgroundColor của UITableViewCell trong nhóm UITableView
- 2. UITextField trong UITableViewCell Trợ giúp
- 3. Làm thế nào để seque một lớp con của UITableViewCell?
- 4. MKMapView bên trong một UITableViewCell
- 5. Làm thế nào để thiết lập một nền UITableViewCell gradient?
- 6. Regex: Làm thế nào để nắm bắt điều này? (một nhóm lồng nhau bên trong một nhóm lặp lại)
- 7. làm thế nào để giảm/loại bỏ lề trái/phải trong một UITableView được nhóm?
- 8. Làm thế nào để tạo một UITextfield đa dòng?
- 9. Làm thế nào để đặt một dòng mới bên trong một chuỗi trong mã nguồn C#?
- 10. Đặt dấu kiểm ở phía bên trái của UITableViewCell
- 11. Đặt tiêu đề chỉ đọc trong một UITextField
- 12. Làm thế nào để đếm các nhóm của cùng một tế bào trong một mảng 2d?
- 13. Android RemoteViews, làm thế nào để thiết lập ScaleType của một ImageView bên trong một widget?
- 14. làm thế nào để làm cho một uitableviewcell không thể chọn
- 15. UIScrollView bên trong một UITableViewCell - No didSelect gọi
- 16. Cần tây - nhóm bên trong một chuỗi
- 17. Làm thế nào để dừng một UIScrollView khỏi tự động cuộn khi một UITextField được chạm vào khung của scrollview?
- 18. Làm thế nào để thêm một điều kiện bên trong của một liên kết trong ngọc?
- 19. Làm thế nào để đặt một biểu tượng bên trong hộp văn bản trong jquery mobile
- 20. Editing TextLabel trong một UITableViewCell
- 21. Làm thế nào để thiết lập hai radio trong một nhóm và hai trong một nhóm khác?
- 22. Làm thế nào để khởi tạo một UITableViewCell từ một nib
- 23. Làm thế nào để kéo lên một UIKeyboard mà không có một UITextField hoặc UITextView?
- 24. Làm thế nào để đặt giữa activityindicator của một tableview
- 25. Làm thế nào để bạn chụp một nhóm với regex?
- 26. Regex: Làm thế nào để có được một tên nhóm
- 27. Làm thế nào để RedirectToAction từ bên trong một ActionFilterAttribute?
- 28. Ruby: Làm thế nào để nhóm một mảng Ruby?
- 29. Làm thế nào để nhóm bởi DESC đặt
- 30. Làm thế nào để ẩn bàn phím khi tôi bấm phím return trong một UITextField?