美文网首页
iOS Swift: anonymous instance no

iOS Swift: anonymous instance no

作者: kinkyboots | 来源:发表于2018-01-30 15:34 被阅读2次

    Problem:

    method of anonymous instance not called.

    let dest = SomeController()
    dest.modalPresentationStyle = .custom
    //new instance, animationController will not be called
    detail.transitioningDelegate = SomeDelegate() 
    present(detail, animated: true, completion: nil)
    

    Cause:

    weak reference

    Solution:

    extract instance to class property

    ...
    fileprivate let mDelegate = SomeDelegate()
    ...
    let dest = SomeController()
    dest.modalPresentationStyle = .custom
    detail.transitioningDelegate = self.mDelegate
    present(detail, animated: true, completion: nil)
    

    相关文章

      网友评论

          本文标题:iOS Swift: anonymous instance no

          本文链接:https://www.haomeiwen.com/subject/hztroxtx.html