Tôi có vấn đề hơi kỳ lạ và tôi không thể hiểu được mình đang thiếu gì. Tôi có một UITableView có thể chỉnh sửa tại chỗ (tức là khi giao diện người dùng của tôi được tải, tôi gửi bảng của tôi setEditing: YES animated: YES message). Hàng cuối cùng trong bảng được dự định là hàng "Thêm mới". Tất cả các hàng ngoại trừ hàng cuối cùng trong bảng của tôi có thể được di chuyển xung quanh. Không thể xóa các hàng nào.Không thể di chuyển các hàng trong UITableView ngay cả khi trình thu thập đang hiển thị
Các hàng hiển thị chính xác và các trình đơn hiển thị ở phía bên phải của tất cả các hàng ngoại trừ hàng cuối cùng (như dự định). Vấn đề là tôi không thể di chuyển các hàng. Khi tôi gõ vào các grabber để di chuyển hàng, nó loại jiggles tại chỗ, nhưng tôi không thể kéo nó lên hoặc xuống. Sau đây là đoạn có liên quan của mã:
- (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return UITableViewCellEditingStyleNone;
}
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [self.itemArray count]) {
return NO;
}
return YES;
}
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == [self.itemArray count]) {
return NO;
}
return YES;
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
Item *item = [self.itemArray objectAtIndex:fromIndexPath.row];
[self.itemArray removeObjectAtIndex:fromIndexPath.row];
[self.itemArray insertObject:item atIndex:toIndexPath.row];
}
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath {
if ([proposedDestinationIndexPath row] < [self.itemArray count]) {
return proposedDestinationIndexPath;
}
NSIndexPath *betterIndexPath = [NSIndexPath indexPathForRow:[self.itemArray count]-1 inSection:0];
return betterIndexPath;
}
Mở cố gắng để gỡ lỗi, có vẻ như rằng tableView: moveRowAtIndexPath: được gọi là gần như ngay lập tức ngay cả khi tôi đang tổ chức sang grabber (tức là tôi đã không nhấc ngón tay của tôi chưa). Hơn nữa, tableView của tôi: targetIndexPathForMoveFromRowAtIndexPath: proposalDestinationIndexPath: không được viện dẫn chút nào.
Bất kỳ suy nghĩ nào về những gì tôi đang làm sai? Bất kỳ đề xuất nào về những gì tôi nên cố gắng khắc phục vấn đề này?
Bản sao có thể có của [Không thể kéo UITableViewCell từ vị trí hiện tại của nó khi sắp xếp lại] (http://stackoverflow.com/questions/9251735/cant-drag-uitableviewcell-from-its-current-position-when-reorder) – Daniel