younatics / MediaBrowser

🏞 A simple iOS photo and video browser with optional grid view, captions and selections written in Swift5.0
https://younatics.github.io/MediaBrowser/
MIT License
649 stars 117 forks source link

Cannot form weak reference to instance of class MediaBrowser. #63

Open cylak opened 5 years ago

cylak commented 5 years ago

Hi, Thanks for your great library! I want to show multiplePhotoGrid() in the first app view controller. But i get this error:

Cannot form weak reference to instance (0x7faf25043a00) of class MediaBrowser.MediaBrowser. It is possible that this object was over-released, or is in the process of deallocation.

And xcode point to line 64 in the MediaBrowser.swift file.

Thanks

AppDelegate.swift

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    window = UIWindow(frame: UIScreen.main.bounds)
    window?.makeKeyAndVisible()
    let mainVC = ViewController()
    window?.rootViewController = mainVC

    return true
}

ViewController.swift

class ViewController: UIViewController, MediaBrowserDelegate {

    var selections = [Bool]()
    var mediaArray = [Media]()
    var thumbs = [Media]()

    override func viewDidLoad() {
        super.viewDidLoad()

        let displayActionButton = true
        let displaySelectionButtons = false
        let displayMediaNavigationArrows = true
        let enableGrid = true
        let startOnGrid = false
        let autoPlayOnAppear = false

        mediaArray = DemoData.multiplePhotoGrid()
        thumbs = DemoData.multiplePhotoGrid()

        let browser = MediaBrowser(delegate: self)
        browser.displayActionButton = displayActionButton
        browser.displayMediaNavigationArrows = displayMediaNavigationArrows
        browser.displaySelectionButtons = displaySelectionButtons
        browser.alwaysShowControls = displaySelectionButtons
        browser.zoomPhotosToFill = true
        browser.enableGrid = enableGrid
        browser.startOnGrid = startOnGrid
        browser.enableSwipeToDismiss = true
        browser.autoPlayOnAppear = autoPlayOnAppear
        browser.cachingImageCount = 2
        browser.setCurrentIndex(at: 1)

        navigationController?.pushViewController(browser, animated: true)

    }

    func numberOfMedia(in mediaBrowser: MediaBrowser) -> Int {
        return mediaArray.count
    }

    func media(for mediaBrowser: MediaBrowser, at index: Int) -> Media {
        if index < mediaArray.count {
            return mediaArray[index]
        }
        return DemoData.localMediaPhoto(imageName: "MotionBookIcon", caption: "Photo at index is Wrong")
    }

}
joshid commented 5 years ago

Same error here. Any tips for workaround this?

nerzh commented 4 years ago

Cool library, but No

voronoff2803 commented 4 years ago

Same error.