UI: 闭包

func chooseMovie(btn:UIButton){


    let movieCtrl = MoviesViewController()
    let appDele = UIApplication.sharedApplication().delegate as! AppDelegate
    let actor = self.actorLabel?.text
    if actor != nil && actor != ""{
    let array = appDele.moviewDict![actor!] as! NSArray
        movieCtrl.dataArray = array
    }

    
    
    
    
    movieCtrl.clickClosure = {
        [weak movieCtrl]
        movieName in
                    self.movieLabel?.text = movieName
        movieCtrl!.dismissViewControllerAnimated(true, completion: nil)
    }
    //感觉闭包的实现方法,可以随便在哪里写。
    //只要不掉用,就没关系。没有对其他代码的 干涉。
    //对象初始化,挂代理,挂闭包。
    
    
    
    
    
    movieCtrl.modalPresentationStyle = .Popover
    movieCtrl.popoverPresentationController?.sourceView = btn
    movieCtrl.popoverPresentationController?.sourceRect = CGRectMake(70, -10, 0, 0)
    movieCtrl.popoverPresentationController?.permittedArrowDirections = .Down
    self.presentViewController(movieCtrl, animated: true, completion: nil)
    
    
}

你可能感兴趣的:(UI: 闭包)