ios - 添加照片到 MWPhotoBrowser

标签 ios uicollectionview mwphotobrowser

我有我的第一个 View Controller imageResults 并在其中使用以下代码调用 MWPhotoBrowser。我看到它使用来自 self.photos 的数据显示了一个新的 View Controller 。我尝试了几个选项来添加更多数据,但都没有成功。我希望能够在新 View 中加载更多数据并将其添加到照片浏览器,添加更多数据部分已经没有,现在如何设置当前浏览器加载新数组而不丢失当前位置?

    -(void)mvTouched:(NSIndexPath *)indexPath {
    NSLog(@"Arr:%lu  Url:%lu", [titlesMutable count], [mediaUrlDict count]);

    NSMutableArray *tmpPhotos = [NSMutableArray array];
    for(NSString *titleString in titlesMutable) {
        NSString *url = [mediaUrlDict objectForKey:titleString];
        MWPhoto *currentPhoto = [MWPhoto photoWithURL:[NSURL URLWithString:url]];
        currentPhoto.caption=[NSString stringWithFormat:@"%@", titleString];
        [tmpPhotos addObject:currentPhoto];
        //[tmpPhotos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:url]]];

    }
    self.photos = [NSArray arrayWithArray:tmpPhotos];


    MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];

    // Set options
    browser.displayActionButton = YES; // Show action button to allow sharing, copying, etc (defaults to YES)
    browser.displayNavArrows = YES; // Whether to display left and right nav arrows on toolbar (defaults to NO)
    browser.displaySelectionButtons = NO; // Whether selection buttons are shown on each image (defaults to NO)
    browser.zoomPhotosToFill = YES; // Images that almost fill the screen will be initially zoomed to fill (defaults to YES)
    browser.alwaysShowControls = YES; // Allows to control whether the bars and controls are always visible or whether they fade away to show the photo full (defaults to NO)
    browser.enableGrid = YES; // Whether to allow the viewing of all the photo thumbnails on a grid (defaults to YES)
    browser.startOnGrid = NO; // Whether to start on the grid of thumbnails instead of the first photo (defaults to NO)
    browser.edgesForExtendedLayout = YES;
    browser.extendedLayoutIncludesOpaqueBars = YES;

    // Optionally set the current visible photo before displaying
    //[browser setCurrentPhotoIndex:1];
    [browser setCurrentPhotoIndex:indexPath.row];

    self.navigationController.navigationBar.hidden=NO;
    // Present
    [self.navigationController pushViewController:browser animated:YES];

    // Manipulate
    [browser showNextPhotoAnimated:YES];
    [browser showPreviousPhotoAnimated:YES];
    //[browser setCurrentPhotoIndex:1];
    [browser setCurrentPhotoIndex:indexPath.row];


    [browser reloadData];
}
-(void)loadMore {
    [self addDataToArray];
    //[self mvTouched:nil];



    [self.collectionView reloadData];

}
- (NSUInteger)numberOfPhotosInPhotoBrowser:(MWPhotoBrowser *)photoBrowser {
    return _photos.count;
}

- (id <MWPhoto>)photoBrowser:(MWPhotoBrowser *)photoBrowser photoAtIndex:(NSUInteger)index {
    if (index < _photos.count)
        return [_photos objectAtIndex:index];
    return nil;
}
- (void)photoBrowser:(MWPhotoBrowser *)photoBrowser actionButtonPressedForPhotoAtIndex:(NSUInteger)index {
    // Do your thing!

    NSLog(@"ACTION!!!");
}

最佳答案

调用 [self.collectionView reloadData] 只会重新加载当前 View 的集合,而不是 MWPhotoBrowser 的。您需要调用浏览器的 reloadData 函数才能像这样工作:

[browser reloadData]

请注意,当前浏览器 Collection View 在调用此方法后不显示新照片存在一个问题。我设法通过将这段代码添加到 MWPhotoBrowser.m 文件中的 reloadData 方法来解决这个问题:

if (_gridController) {
    [_gridController.collectionView reloadData];
}

关于ios - 添加照片到 MWPhotoBrowser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26006453/

相关文章:

ios - 如何在快速按下按钮时添加一个独立的 UIView?

ios - 如何将 UITextField 添加到 CALayer 并使其工作

ios - PhoneGap- 屏幕方向不适用于 iOS 中的照片库

ios - 滚动时在UITableView中重复数据

ios - 实现照片浏览器 View

ios - 即使采取措施后,UICollectionView 单元格重用也会导致问题

ios - 覆盖 UICollectionView 子类中的委托(delegate)和数据源 setter

ios - UICollectionView cellForItemAtIndexPath indexPath 行为零

ios - MWPhotoBrowser - 导航栏在 iOS 8 中消失

iOS:快速滚动照片时出错?