Skip to content

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

@cylak

Description

@cylak

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")
    }

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions