Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Hochunseng opened this issue Jul 28, 2018 · 2 comments

Comments

@Hochunseng
Copy link

Hochunseng commented Jul 28, 2018

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
Copy link

fparkar commented Aug 1, 2018

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

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

@Hochunseng
Copy link
Author

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants