- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
if(editingStyle == UITableViewCellEditingStyleDelete){
//[theSimpsons removeObjectAtIndex:indexPath.row];
NSString *time = [[arrayList objectAtIndex:indexPath.row] objectForKey:@"TIME"];
NSString *date= [[arrayList objectAtIndex:indexPath.row] objectForKey:@"DATE"];
DBManager *dbm = [[DBManager alloc] init];
[dbm initiallzeDatabase];
[dbm deleteItemAtIndexPath:time :date];
//arrayList = [dbm getParkResults];
//[parkTableView reloadData];
[arrayList removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
}
Tôi đã sử dụng mã ở trên trong ứng dụng của mình. Phần chỉnh sửa hoạt động tốt, nhưng vấn đề là, nút xóa chỉ xuất hiện khi chúng tôi vuốt từ trái sang phải trên một ô. Bây giờ tôi có một menu mở ra từ trái sang phải như Facebook. Vậy làm cách nào tôi có thể đảm bảo rằng nút xóa xuất hiện khi người dùng vuốt từ phải sang trái.Muốn hiển thị nút xóa trên vuốt từ phải sang trái trong UITableView
Tôi đưa ra một thử này. Khi bạn nói hiển thị nút Xóa, chúng tôi có thể hiển thị nút xóa mặc định theo chương trình không? Nếu có thì làm thế nào? Cảm ơn :) – ScarletWitch
Bạn có thể thử đặt loại ô bảng thành 'UITableViewCellEditingStyleDelete' khi vuốt sang trái. Hoặc tạo lớp con của 'UITableViewCell' và vẽ ô đó thay vì ô mặc định cho hàng đó. – Gossamer
Vâng. Điều này được thực hiện công việc vừa phải. Cảm ơn Gossamer. :) – ScarletWitch