Reputation:
In ViewController :
protocol SearchResultDelegate {
func SendDataToResultController(_ result: [SkelbimasModel])
}
class ViewController: UIViewController, UISearchBarDelegate, CLLocationManagerDelegate, MKMapViewDelegate, AddSkelbimas {
@IBOutlet weak var Label: UILabel!
@IBOutlet weak var SearchBar: UISearchBar!
// @IBOutlet weak var boomFilter: BoomMenuButton!
// @IBOutlet weak var Label: UILabel!
@IBOutlet weak var CategoryView: UIView!
@IBOutlet weak var Map: MKMapView!
@IBOutlet weak var bmb: BoomMenuButton!
var Delegate:SearchResultDelegate?
.........
//ijungimiame lentele su paieskos rezultatais
if(result.count > 1) {
Delegate?.SendDataToResultController(result)
GoToSearchResultVC(result)
}
Function GoToSearchResultVC(result) is called it opens new controller in that new controller code is :
import UIKit
class SearchResultTableViewController: UITableViewController, SearchResultDelegate {
.....
func SendDataToResultController(_ result: [SkelbimasModel]) {
print("result count: \(result.count)")
results = result
}
But this function is never called. I used delegates before and was fine. Or i'm just tired and do not see where i did wrong...
Upvotes: 0
Views: 2151
Reputation: 76
If you are showing after SearchResultTableViewController from ViewController, isn't it easier to do something like:
func GoToSearchResultVC(result: Any) {
let searchVC = SearchResultTableViewController()
searchVC.results = results
self.present(searchVC, animated: true, completion: nil)
}
Delegate design patter is to receive events from other classes, if you only want to set a variable, this way is better for me
BTW checking your code, you are calling first the delegate before creating the SearchResultsVC
Upvotes: 0
Reputation: 19737
Somewhere where you create the ViewController
in your code in SearchResultTableViewController
you have to set the value of the delegate:
let viewController = ViewController()
viewController.Delegate = self
// present viewController
Upvotes: 3