美文网首页
Swift 通知NSNotificationCenter use

Swift 通知NSNotificationCenter use

作者: chayc | 来源:发表于2016-10-11 13:28 被阅读0次
    NSNotificationCenter.defaultCenter().postNotificationName(ZYShowPhotoBrowserController, object: self, userInfo: ["bmiddle_pic": self.viewModel!.bmiddle_pic!, "indexPath": indexPath])
    
    

    //注册通知
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(HomeTableViewController.showBrowser(_:)), name: ZYShowPhotoBrowserController, object: nil)
    
    deinit{
        //移除通知
        NSNotificationCenter.defaultCenter().removeObserver(self)
    }
    
    @objc private func showBrowser(notice: NSNotification)
    {
         guard let pictures = notice.userInfo!["bmiddle_pic"] as? [NSURL] else{
                
              return
         }
         guard let index = notice.userInfo!["indexPath"] as? NSIndexPath else{
                
              return
        }
            
        let vc = ZYBrowserViewController(bmiddle_pic: pictures, indexPath: index)
        presentViewController(vc, animated: true, completion: nil)
    }
    
    

    相关文章

      网友评论

          本文标题:Swift 通知NSNotificationCenter use

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