thể trùng lặp:
How to do edit-in-place in a UITableView?Editing TextLabel trong một UITableViewCell
Tôi mới vào iphone phát triển này. Tôi chỉ muốn biết cách chỉnh sửa/cập nhật UITextLabel trong một tableView.
Tôi đã sử dụng hoạt ảnh chỉnh sửa/thực hiện và có thể xóa các hàng nhưng tôi không thể biết cách chỉnh sửa văn bản trong các hàng đó.
Tôi muốn người dùng chỉnh sửa nhãn văn bản của ô.khi chỉnh sửa nút được nhấn.
tôi đã tìm kiếm trang web nhưng không thể nhận được câu trả lời chính xác.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifier"];
if(!cell)
{
cell = [[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CellIdentifier"]autorelease];
cell.editingAccessoryType=YES;
}
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(15, 6, 241, 31)];
myTextField.backgroundColor = [UIColor clearColor];
myTextField.textAlignment = UITextAlignmentLeft;
myTextField.returnKeyType = UIReturnKeyDone;
myTextField.delegate = self;
cell.accessoryView = myTextField;
myTextField.text = [self.arrayOfItems objectAtIndex:indexPath.row];
myTextField.enabled = NO;
return cell;
}
-(IBAction)Edit:(id)sender
{
if(self.editing)
{
[myTextField.Enabled = YES];
[super setEditing:NO animated:NO];
[self.tab setEditing:NO animated:NO];
[self.tab reloadData];
[self.navigationItem.rightBarButtonItem setTitle:@"Done"];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStylePlain];
}
else
{
myTextField.enabled= YES;
[super setEditing:YES animated:YES];
[self.tab setEditing:YES animated:YES];
[self.tab reloadData];
[self.navigationItem.rightBarButtonItem setTitle:@"Edit"];
[self.navigationItem.rightBarButtonItem setStyle:UIBarButtonItemStyleDone];
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (self.editing == NO || !indexPath)
return UITableViewCellEditingStyleNone;
if (self.editing && indexPath.row == ([self.arrayOfItems count]))
{
return UITableViewCellEditingStyleInsert;
}
else
{
return UITableViewCellEditingStyleDelete;
}
return UITableViewCellEditingStyleNone;
}
Đây không phải đang làm việc cho me.textfield đang biến mất nếu tôi nhấn nút chỉnh sửa
Trong khi điều này không thực sự trả lời câu hỏi về cách thực hiện chỉnh sửa văn bản trong bảng, nó trình bày một số điểm hợp lệ vì sao nó có thể không phải là ý tưởng hay trong mọi trường hợp. –