mwaterfall / MWPhotoBrowser

A simple iOS photo and video browser with grid view, captions and selections.
MIT License
8.75k stars 2.71k forks source link

Getting black screen when I push browser to navigation controller, what am I doing wrong? #639

Open Hochunseng opened 6 years ago

Hochunseng commented 6 years ago

Here is the setup I have so far:

import UIKit
import MWPhotoBrowser

class PhotoViewController: UINavigationController, MWPhotoBrowserDelegate {

    var photos  = [MWPhoto]()

    override func viewDidLoad() {
        super.viewDidLoad()
        retrievePics()
        initiateBrowser()
    }

    func initiateBrowser() {
        let browser = MWPhotoBrowser(delegate: self)

        browser?.displayActionButton = true // Show action button to allow sharing, copying, etc (defaults to YES)
        browser?.displayNavArrows = false // Whether to display left and right nav arrows on toolbar (defaults to NO)
        browser?.displaySelectionButtons = false // Whether selection buttons are shown on each image (defaults to NO)
        browser?.zoomPhotosToFill = true // Images that almost fill the screen will be initially zoomed to fill (defaults to YES)
        browser?.alwaysShowControls = false // 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 = true // Whether to allow the viewing of all the photo thumbnails on a grid (defaults to YES)
        browser?.startOnGrid = false // Whether to start on the grid of thumbnails instead of the first photo (defaults to NO)

        self.navigationController?.pushViewController(browser!, animated: true)

    }

    func numberOfPhotos(in photoBrowser: MWPhotoBrowser!) -> UInt {
        return UInt(photos.count)
    }

    func photoBrowser(_ photoBrowser: MWPhotoBrowser!, photoAt index: UInt) -> MWPhotoProtocol! {
        let realIndex : Int = Int(index)
        if index < photos.count {
            return photos[realIndex]
        }
        return nil
    }

}

I'm omitting my retrievePics() function for privacy purposes but essentially it converts UIImages to MWPhoto objects and appends them to the photos array.

fparkar commented 6 years ago

print the retrievePics() & make sure photos have data.

Black screen means you are not passing any images array...

Hochunseng commented 6 years ago

Ok I printed the photos array and it looks like the browser is initiated before the pictures are appended to the photos array through retrievePics(). In my ViewDidLoad I am calling retrievePics() then initiateBrowser() but the browser finishes initiating before any of the pictures are appended. How can I make sure all the pictures are appended before the browser is initiated?