title: How can I use same table view more than one textfield in Swift 3
body: <p>Hey everyone I am using a text field for search. When I search something, listing data on searchresultvc. And here If I click any row, showing detail of data another VC. Everything ok for here. Problem begins after here. If I search anything on searchresultvc (there is a another textfield), data listing again. But I can't click any row. I am getting error: 'fatal error: Index out of range'.(How can I do effiecently and with at least code)</p>
  
  <p>My ViewController:</p>
  
  <pre><code>@IBOutlet weak var searchTextField: UITextField!
  var cName = [String]()
  var kTitle = [String]()
  var cId = [Int]()
  
  override func viewDidLoad() {
      super.viewDidLoad()
      // Do any additional setup after loading the view, typically from a nib.
  }
  
  @IBAction func searchButton(_ sender: Any) {
      let headers: HTTPHeaders = [
          "Authorization": "Basic ...",
          "content-type": "application/json"
      ]
  
      let encodedSearchText = searchTextField.text?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
  
      if let searchText = encodedSearchText{
  
          Alamofire.request("..../api/GetSearchResult?searchText=\(searchText)", headers: headers).responseJSON { (response) in
              if response.result.value != nil{
                  let swiftyJsonVar = JSON(response.result.value!)
  
                  for i in 0...swiftyJsonVar.count{
                      self.cName.append(String(describing: swiftyJsonVar[i]["..."]))
                      self.kTitle.append(String(describing: swiftyJsonVar[i]["..."]))
                      self.cId.append(swiftyJsonVar[i]["contentId"].intValue)
                  }
  
                  let srvc = self.storyboard?.instantiateViewController(withIdentifier: "SearchResultVC") as! SearchResultViewController
                  srvc.crName = self.cName
                  srvc.krTitle = self.kTitle
                  srvc.ctId = self.cId
                  self.present(srvc, animated: true, completion: nil)
              }
  
          }
      }
  }
  </code></pre>
  
  <p>And My SearchResult View Controller:</p>
  
  <pre><code>@IBOutlet weak var searchTextField: UITextField!
  @IBOutlet weak var tableView: UITableView!
  
  var crName = [String]()
  var krTitle = [String]()
  var ctId = [Int]()
  var krDetail = String()
  var krSource = String()
  
  @IBOutlet weak var dataCount: UILabel!
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
      // Do any additional setup after loading the view.
      dataCount.text = String(crName.count)
  }
  
  func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -&gt; Int {
      return crName.count
  }
  
  func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -&gt; UITableViewCell {
  
      let cell = tableView.dequeueReusableCell(withIdentifier: "resultCell", for: indexPath) as! SearchResultCellTableViewCell
  
      cell.kr.text = krTitle[indexPath.row]
      cell.cr.text = crName[indexPath.row]
      return cell
  }
  
  func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -&gt; CGFloat {
      return 100
  }
  
  func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      let headers: HTTPHeaders = [
          "Authorization": "Basic ...",
          "content-type": "application/json"
      ]
      Alamofire.request(".../api/GetResultById?contentId=\(contentId[indexPath.row])", headers: headers).responseJSON { (response) in
          if response.result.value != nil{
              let swiftyJsonVar = JSON(response.result.value!)
  
              self.krDetail = String(describing: swiftyJsonVar[0]["..."]).stringByDecodingHTMLEntities
              self.krSource = String(describing: swiftyJsonVar[0]["..."]).stringByDecodingHTMLEntities
              let resultVC = self.storyboard?.instantiateViewController(withIdentifier: "ResultVC") as! ContentResultViewController
              resultVC.course = self.crName[indexPath.row]
              resultVC.content = self.krTitle[indexPath.row]
              resultVC.cDesc = self.krDetail.removeHtmlFromString(inPutString: self.krDetail)
              resultVC.cSource = self.krSource.removeHtmlFromString(inPutString: self.krSource)
              self.present(resultVC, animated: true, completion: nil)
          }
      }
  }
  
  
  @IBAction func search(_ sender: Any) {
      let headers: HTTPHeaders = [
          "Authorization": "Basic ...",
          "content-type": "application/json"
      ]
  
      let encodedSearchText = searchTextField.text?.addingPercentEncoding(withAllowedCharacters: .urlHostAllowed)!
  
      if let searchText = encodedSearchText{
  
          Alamofire.request(".../api/GetSearchResult?searchText=\(searchText)", headers: headers).responseJSON { (response) in
              if response.result.value != nil{
                  let swiftyJsonVar = JSON(response.result.value!)
                  self.crName = []
                  self.krTitle = []
                  for i in 0...swiftyJsonVar.count{
                      self.crName.append(String(describing: swiftyJsonVar[i]["...."]))
                      self.krTitle.append(String(describing: swiftyJsonVar[i]["..."]))
                  }
  
                  let srvc = self.storyboard?.instantiateViewController(withIdentifier: "SearchResultVC") as! SearchResultViewController
                  srvc.crName = self.crName
                  srvc.krTitle = self.krTitle
                  self.tableView.reloadData()
  
                  self.present(srvc, animated: false, completion: nil)
              }
  
          }
      }
  }
  </code></pre>