iOS:未加载MWPhotoBrowser图像子类的Viewcontroller

时间:2015-08-13 14:43:16

标签: ios objective-c iphone storyboard mwphotobrowser

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

  1. 当它在样品中使用时,它工作正常。
  2. 但是当一个新的viewcontroller从MWPhotoBrowser子类化时,除了空的黑色主题外,不会加载照片。
  3. 不会调用委托方法。由于控制器是MWPhotoBrowser的子类,我假设不需要明确设置它。
  4. 使用Storyboard并设置其中的nib类。
  5. .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 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];
    }
    

    已执行调试

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

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

1 个答案:

答案 0 :(得分: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初始化器。