如何在下一个ViewController中的事件发生后在UICollectionView Cell的最后一个索引处重新排序?

时间:2019-03-16 08:14:51

标签: uicollectionview uicollectionviewcell uipageviewcontroller nsindexpath

当用户按下我的collectionView中的单元格时,他得到一个UIPageViewController。然后,当他完成滚动并查看最后一个图像时,关闭视图并返回到上一个集合视图控制器,我需要他刚刚按下的单元格成为collectionViewCell列表的最后一个。我真的不知道该怎么办?

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

    id model = self.dataList.data[indexPath.row];
    CollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
    [self setupCell:cell withModel:model atIndexPath:indexPath];

    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{     
    Model *model = self.dataList.data[indexPath.row];
    UIStoryboard *sb = [UIStoryboard storyboardWithName:@"SB" bundle:nil];
    PageViewController *vc = [sb instantiateViewControllerWithIdentifier:@"PageVC"];
    [self presentViewController:vc animated:YES completion:nil];
}

PageViewController中的代码

- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController
{
    NSUInteger index = ((ViewController *)viewController).pageIndex;
    if (index == NSNotFound) {
        return nil;
    }
    index++;
    if (index == self.images.count) {
        return nil;
    }
    return [self viewControllerAtIndex:index];
}

0 个答案:

没有答案