关注UICollectionViewCell

时间:2015-01-30 09:58:10

标签: ios uicollectionview uiimagepickercontroller uicollectionviewcell

我有一个UICollectionView由一个单元格中的UIImagePickerControl按钮填充,我希望集合视图末尾的单元格跟在屏幕上,但仍然启用用户滚动

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{
NSString* imageString = [image toString];
Screen * screen = [[Screen alloc]init];
screen.imageData = imageString;
[self.project.screens addObject:screen];
long long rowid = [self saveNewImageForScreenToDb:screen];
[self updateTitle:@"" atRowId:rowid];
[self updateTask:@"" atRowId:rowid];


[self dismissViewControllerAnimated:_picker completion:^{
    [_collectionView reloadData];

}];

    NSIndexPath * indexPath = [[NSIndexPath alloc]initWithIndex:?]; 
   [self.collectionView scrollToItemAtIndexPath: indexPath.row =?
                                atScrollPosition:UICollectionViewScrollPositionRight
                                        animated:YES];

}

这是选择器的代码,选择器是我的'UICollectioView'末尾的按钮。必须插入什么indexPath才能让屏幕滚动到按钮

的末尾

1 个答案:

答案 0 :(得分:1)

您可以将所选图片添加到NSMutableArray。假设您的数组为imagesArray。将collectionView滚动到NSMutableArray的最后一个对象。尝试在didFinishPickingImage方法下添加此代码。

[_collectionView reloadData];
NSIndexPath *bottomIndexPath=[NSIndexPath indexPathForRow:imagesArray.count-1 inSection:0];
[self.collectionView scrollToItemAtIndexPath: bottomIndexPath atScrollPosition:UICollectionViewScrollPositionRight animated:YES];