在编辑按钮上删除UICollectionView单元格

问题描述 投票:3回答:2

我正在使用UICollectionView来检索存储在Cloud数据库Parse中的图像和标签。

我现在需要一个选项,让我删除某个图像及其相应的标签。

我正在寻找一些东西,比如右上角的典型iPhone“编辑”按钮,它会在单元格旁边显示一个带有删除按钮的滑动动画。我知道这样的事情可以在UITableView上完成

[[self tableView] setEditing:YES animated:YES];

但我似乎无法在任何地方找到UICollectionView的等价物。

任何帮助,即使它不处理从Parse本身的删除,只是集合视图上的编辑样式将是理想的。

以下是我填充单元格的方法:

- (void)viewDidLoad
{
   [super viewDidLoad];
   [self retrieveSelectedImages];
}

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return [imageFilesArray count];
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {

static NSString *cellIdentifier = @"myRoomsCell";
MyRoomsCell *cell = (MyRoomsCell *)[collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

PFObject *imageObject = [imageFilesArray objectAtIndex:indexPath.row];
PFFile *imageFile = [imageObject objectForKey:@"imageFile"];

cell.loadingSpinner.hidden = NO; //show loading spinner to indicate work is happening until the image loads
[cell.loadingSpinner startAnimating];

// UILabel *label = (UILabel*) [cell viewWithTag:5];
cell.label.text= [imageObject objectForKey:@"roomLabel"]; //set room label as the label stored on parse previously inserted by the user

cell.label.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
cell.label.textAlignment = NSTextAlignmentCenter;


[imageFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error)
{
    if (!error) {
        cell.parseImage.image = [UIImage imageWithData:data];
        [cell.loadingSpinner stopAnimating];
        cell.loadingSpinner.hidden = YES;
    }
}];

return cell;
}

-(void) retrieveSelectedImages
{
//parse query where we search the favorites array column and return any entry where the array contains the logged in user objectid
PFQuery *getFavorites = [PFQuery queryWithClassName:@"collectionViewData"];
[getFavorites whereKey:@"selectedImage" equalTo:[PFUser currentUser].objectId];

[getFavorites findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) {
    if (!error)
    {
        imageFilesArray = [[NSArray alloc] initWithArray:objects];
        [roomsCollection reloadData];
    }
}];
}
objective-c uitableview parse-platform uicollectionview uicollectionviewcell
2个回答
3
投票

看看这个答案有很多代码供您试用:https://stackoverflow.com/a/16190291/1914567

基本上,没有Apple提供的方法来做到这一点。

还有一些非常好的图书馆。我个人最喜欢的是DraggableCollectionView,还可以看看LXReorderableCollectionViewFlowLayout


-3
投票
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    [[Singleton sharedSingleton].selectedProfileArray removeObjectAtIndex:indexPath.row];
    [selectCollectionView reloadData];
}
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.