iOS: Viewcontroller subclassed from MWPhotoBrowser-images are not loaded

169 Views Asked by At

I am trying to include MWPhotoBrowser in my project

  1. When its used as given in the sample it working fine.
  2. But when a new viewcontroller is subclassed from MWPhotoBrowser, photos are not loaded except empty black theme.
  3. Delegate methods are not getting called. As the controller is subclass of MWPhotoBrowser, I assume there is no need to set it explicitly.
  4. Storyboard is used and the nib class in it is set.

.h file

@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 file **

- (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];
}

Debugging performed

Considering the image template of mwphotobrowser, tried reloading the code. Shifted the code between viewwillappear and viewdidload.

Doesn't MWPhotoBrowser support this way or am i doing it wrong ?

1

There are 1 best solutions below

0
On

For those who stumble upon this later...

If you look at MWPhotoBrowser.m you'll see various initializers:

- (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;
}

The problem is there's no awakeFromNib initializer. Simplest solution is to fork the project and create the awakeFromNib initializer.