首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将照片添加到MWPhotoBrowser

将照片添加到MWPhotoBrowser
EN

Stack Overflow用户
提问于 2014-09-23 23:53:26
回答 1查看 1.6K关注 0票数 0

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

代码语言:javascript
复制
    -(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!!!");
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-10-02 16:21:09

调用self.collectionView reloadData只会重新加载当前视图的集合,而不是MWPhotoBrowser的集合。为此,需要调用浏览器reloadData函数,如下所示:

代码语言:javascript
复制
[browser reloadData]

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

代码语言:javascript
复制
if (_gridController) {
    [_gridController.collectionView reloadData];
}
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/26006453

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档