Tôi có một ứng dụng dựa trên UICollectionView đơn giản - một UICollectionView và một mô hình dữ liệu dựa trên NSMutableArray để đơn giản.Xóa các ô khỏi UICollectionView qua NSNotification
tôi có thể xóa các tế bào không có vấn đề thông qua didSelectItemAtIndexPath: Phương pháp đại biểu:
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[self.data removeObjectAtIndex:[indexPath row]];
[self.collectionView deleteItemsAtIndexPaths:@[indexPath]];
}
Tuy nhiên, tôi đang cố gắng để thêm một tùy chọn xóa thông qua một UIMenuController
trong một lớp con UICollectionViewCell
mà được kích hoạt thông qua một UILongPressGestureRecognizer
mà tất cả hoạt động tốt và tôi thành công kích hoạt NSNotification
-(void)delete:(id)sender{
NSLog(@"Sending deleteme message");
[[NSNotificationCenter defaultCenter] postNotificationName:@"DeleteMe!" object:self userInfo:nil];
}
tôi bắt nó trong ViewController của tôi và gọi phương thức sau đây:
-(void)deleteCell:(NSNotification*)note{
MyCollectionViewCell *cell = [note object];
NSIndexPath *path = nil;
if((path = [self.collectionView indexPathForCell:cell]) != nil){
[self.data removeObjectAtIndex:[path row]];
[self.collectionView deleteItemsAtIndexPaths:@[path]];
}
}
Và nó bị treo trên deleteItemsAtIndexPaths: gọi
-[UICollectionViewUpdateItem action]: unrecognized selector sent to instance 0xee7eb10
Tôi đã kiểm tra tất cả mọi thứ rõ ràng - như các đối tượng từ NSNotification và indexPath tạo từ indexPathForCell: gọi và tất cả dường như hoàn toàn tốt. Có vẻ như tôi đang gọi deleteItemsAtIndexPath: với cùng một thông tin ở cả hai nơi, nhưng vì một số lý do nó không thành công khi nó đi qua tuyến thông báo.
Đây là thông tin tại địa chỉ được đưa ra trong các lỗi:
(lldb) po 0xee7eb10
(int) $1 = 250080016 <UICollectionViewUpdateItem: 0xee7eb10> index path before update (<NSIndexPath 0x9283a20> 2 indexes [0, 0]) index path after update ((null)) action (delete)
Có lẽ con đường chỉ số sau khi cập nhật là null là đáng kể ...
Bất kỳ ý tưởng?
trong 'deleteCell:' bạn sử dụng 'self.collectionViewOne' và 'self.collectionView' - đó là mục đích? –
xin lỗi - đó là lỗi đánh máy. – melps
Tôi có thể xác nhận điều này cũng xảy ra khi chèn các mục mới từ một thông báo. – Brett