0

我正在尝试在我的项目中包含 MWPhotoBrowser

  1. 当它按照示例中给出的方式使用时,它工作正常。
  2. 但是当一个新的视图控制器从 MWPhotoBrowser 子类化时,除了空的黑色主题之外,不会加载照片。
  3. 委托方法没有被调用。由于控制器是 MWPhotoBrowser 的子类,我认为不需要显式设置它。
  4. 使用故事板并设置其中的 nib 类。

.h 文件

@interface MDRPhotoViewerController : MWPhotoBrowser
{
    NSMutableArray *_selections;
}
@property (nonatomic, strong) NSMutableArray *photos;
@property (nonatomic, strong) NSMutableArray *thumbs;
@property (nonatomic, strong) NSMutableArray *assets;
@property (nonatomic, strong) NSMutableIndexSet *optionIndices;
@property (nonatomic, strong) UITableView *tableView;

@property (nonatomic, strong) ALAssetsLibrary *ALAssetsLibrary;

- (void)loadAssets;
@end

**.m 文件 **

- (void)viewWillAppear:(BOOL)animated
{
   NSMutableArray *photos = [[NSMutableArray alloc] init];
    NSMutableArray *thumbs = [[NSMutableArray alloc] init];
//mwphotobrowser options setup
    BOOL displayActionButton = YES;
    BOOL displaySelectionButtons = NO;
    BOOL displayNavArrows = NO;
    BOOL enableGrid = YES;
    BOOL startOnGrid = NO;
    BOOL autoPlayOnAppear = NO;

    //loading data
    NSArray *photosDataArray = [MDRDataController GetPhotos]; //creating array
    for (NSString *urlString in photosDataArray) { //Formating the data source for images
        NSString *urlFullString = [NSString stringWithFormat:@"%@%@",KBASEURL,urlString];
        //Photos
        [photos addObject:[MWPhoto photoWithURL:[NSURL URLWithString:urlFullString]]];
        //thumbs
        [thumbs addObject:[MWPhoto photoWithURL:[NSURL URLWithString:urlFullString]]];

    }
    // Options
    self.photos = photos;
    self.thumbs = thumbs;

    // Create browser
    self.displayActionButton = displayActionButton;
    self.displayNavArrows = displayNavArrows;
    self.displaySelectionButtons = displaySelectionButtons;
    self.alwaysShowControls = displaySelectionButtons;
    self.zoomPhotosToFill = YES;
    self.enableGrid = enableGrid;
    self.startOnGrid = startOnGrid;
    self.enableSwipeToDismiss = NO;
    self.autoPlayOnAppear = autoPlayOnAppear;
    [self setCurrentPhotoIndex:0];

    // Test custom selection images
    //    browser.customImageSelectedIconName = @"ImageSelected.png";
    //    browser.customImageSelectedSmallIconName = @"ImageSelectedSmall.png";

    // Reset selections
    if (displaySelectionButtons) {
        _selections = [NSMutableArray new];
        for (int i = 0; i < photos.count; i++) {
            [_selections addObject:[NSNumber numberWithBool:NO]];
        }
    }
    self.title = @"Phots";
    //[self reloadData];
}

已执行调试

考虑到mwphotobrowser的图像模板,尝试重新加载代码。在 viewwillappear 和 viewdidload 之间移动了代码。

MWPhotoBrowser 不支持这种方式还是我做错了?

4

1 回答 1

0

对于那些后来偶然发现的人......

如果您查看 MWPhotoBrowser.m,您会看到各种初始化程序:

- (id)init {
if ((self = [super init])) {
    [self _initialisation];
}
return self;
}

- (id)initWithDelegate:(id <MWPhotoBrowserDelegate>)delegate {
    if ((self = [self init])) {
        _delegate = delegate;
    }
    return self;
}

- (id)initWithPhotos:(NSArray *)photosArray {
    if ((self = [self init])) {
        _fixedPhotosArray = photosArray;
    }
    return self;
}

- (id)initWithCoder:(NSCoder *)decoder {
    if ((self = [super initWithCoder:decoder])) {
        [self _initialisation];
    }
    return self;
}

问题是没有 awakeFromNib 初始化程序。最简单的解决方案是分叉项目并创建 awakeFromNib 初始化程序。

于 2016-03-09T15:18:31.340 回答