SHARE
TWEET

Untitled

a guest Jul 22nd, 2019 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var folder_Comany = [FoldeCompanyDetails]()
  2.  
  3. var filterData = [FoldeCompanyDetails]()
  4.  
  5.  var searchActive : Bool = true
  6.  
  7.     override func viewDidLoad() {
  8.         super.viewDidLoad()
  9.  
  10.          searchCompany()
  11.         // Do any additional setup after loading the view.
  12.     }
  13.  
  14.  
  15.  
  16.  func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String)
  17.  
  18. {
  19.  
  20.  
  21.   guard !searchText.isEmpty else {
  22.  
  23.     filterData = folder_Comany
  24.  
  25.             listView.reloadData()
  26.  
  27.             return
  28.         }
  29.  
  30.  
  31.  filterData =  folder_Comany.filter({ (FoldeCompanyDetails) -> Bool in
  32.             (FoldeCompanyDetails.folderItemCompanyName?.lowercased().contains(searchText.lowercased()))!
  33.         })
  34.         listView.reloadData()
  35.  
  36.     }
  37.  
  38.     func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
  39.         self.searchPicker.endEditing(true)
  40.     }
  41.  
  42.  
  43.  
  44.  
  45. func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
  46.  
  47.  
  48.  if(searchActive) {
  49.  
  50.  return filterData.count
  51.  
  52.         }
  53.  
  54.  
  55.         return folder_Comany.count
  56.  
  57.     }
  58.  
  59.     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
  60.  
  61.         let cell = tableView.dequeueReusableCell(withIdentifier:"CompanyCell",for: indexPath) as! CompanyNameCell
  62.  
  63.         if(searchActive){
  64.  
  65.             cell.companyNameLabel.text = filterData[indexPath.row].folderItemCompanyName
  66.  
  67.         }
  68.  
  69.         else {
  70.  
  71.             cell.companyNameLabel.text  = folder_Comany[indexPath.row].folderItemCompanyName
  72.         }
  73.  
  74.         self.listView.rowHeight = 45.0
  75.  
  76.         return cell
  77.     }
  78.  
  79.  
  80.     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
  81.  
  82.         if (searchActive){
  83.  
  84.  
  85.             UserDefaults.standard.set(filterData[indexPath.row].folderItemCompanyName, forKey: "SaveCompanyName")
  86.             UserDefaults.standard.set(filterData[indexPath.row].folderItemCompanyId, forKey: "SaveCompanyID")
  87.             let storyboard = UIStoryboard(name: "Home", bundle: nil)
  88.             let controller = storyboard.instantiateViewController(withIdentifier: "showoffice") as! ShowOffice
  89.             controller.officeName = filterData[indexPath.row].folderItemCompanyName
  90.             controller.officeID = filterData[indexPath.row].folderItemCompanyId
  91.             self.navigationController?.pushViewController(controller, animated: true)
  92.  
  93.  
  94.         }
  95.  
  96.  
  97.         else{
  98.  
  99.             UserDefaults.standard.set(folder_Comany[indexPath.row].folderItemCompanyName, forKey: "SaveCompanyName")
  100.             UserDefaults.standard.set(folder_Comany[indexPath.row].folderItemCompanyId, forKey: "SaveCompanyID")
  101.             let storyboard = UIStoryboard(name: "Home", bundle: nil)
  102.             let controller = storyboard.instantiateViewController(withIdentifier: "showoffice") as! ShowOffice
  103.             controller.officeName = folder_Comany[indexPath.row].folderItemCompanyName
  104.             controller.officeID = folder_Comany[indexPath.row].folderItemCompanyId
  105.             self.navigationController?.pushViewController(controller, animated: true)
  106.  
  107.  
  108.         }
  109.  
  110.  
  111.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top