我希望将电影的数据传递到另一个控制器,并在完成进度后再通过另一个控制器。我可以用一个segue做这个吗?
class LoadingScreenViewController: UIViewController {
var movies = [Movie]()
@IBOutlet weak var progress: UIProgressView!
@IBOutlet weak var countLabel: UILabel!
override func viewDidLoad()
{
NSTimer.scheduledTimerWithTimeInterval(1, target: self, selector: #selector(LoadingScreenViewController.updateProgress), userInfo: nil, repeats: true)
progress.setProgress(0, animated: true)
}
func updateProgress () {
if progress.progress != 1 {
self.progress.progress += 2 / 10
} else {
UIView.animateWithDuration(0.4, animations: { () -> Void in
})
performSegueWithIdentifier("segue", sender:self)
progress.hidden = true
self.countLabel.hidden = true
}
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
let controller : SearchViewController = segue.destinationViewController as! SearchViewController
if segue.identifier == "segue"{
controller.model = movies
}
}
}
答案 0 :(得分:0)
请执行以下操作: -
extension UIViewController {
func addSearchController() {
let searchController = UISearchController(searchResultsController: nil)
self.view.addSubview(searchController.searchBar)
}
}
只需在所需VC的viewDidLoad方法中调用self.addSearchController()方法即可。无需传递SearchController。