2016-01-18 81 views
1

的視圖控制器,它有兩個views.in第一ViewController有一個tableview。當第一個單元格從tableview選擇,它加載另一種觀點與其它tableview與搜索選項。然後從tableview的搜索結果中,選擇一個單元格後,當前視圖應該消除。爲什麼不能排除在我的應用程序在didSelectRowAtIndexPath方法方法

  • 我的第一個問題是我無法從搜索結果中選擇一個單元格direclty。我必須點擊兩次。
  • 我的第二個問題是不能dimiss的viewcontroller

這是我的代碼

- (void)updateSearchResultsForSearchController:(UISearchController *)searchController 
{ 
    NSString *enteredString = searchController.searchBar.text; 
    if ([enteredString length] >= 3) { 
      [self getAirportCodesFromWebService:enteredString]; 
    } 
    [self.airportTable reloadData]; 
} 


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
{ 
    return 1; 
} 

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{ 
    return [airportArray count]; 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    GetAirportTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"reuse" forIndexPath:indexPath]; 

    GetAirport *getAirports = [airportArray objectAtIndex:indexPath.row]; 
    cell.AirportName.text = getAirports.AirportName; 

    return cell; 
} 


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    GetAirport *getAirports = [airportArray objectAtIndex:indexPath.row]; 
    NSString *selectedAirport = getAirports.AirportName; 
    [[NSUserDefaults standardUserDefaults] setObject:selectedAirport forKey:@"selectedairport"]; 
    [[NSUserDefaults standardUserDefaults] synchronize]; 

    [self dismissViewControllerAnimated:YES completion:nil]; 

} 

我用UISearchController編程爲searh.inside它,我根據用戶inputs.help我呼籲web服務這個

+0

你是怎麼來到這第二個視圖控制器的 –

+0

把fisrt'cell'拖到新的控制檯上並選擇'show'作爲'Storyboard segue' –

+0

你可以試試模態..? –

回答

3

首先,在你的第二個視圖控制器中,你有一個帶有搜索欄的tableview。

  • 所以這tableview中有自己的代表&數據源的方法 當您嘗試搜索在搜索欄什麼,搜索欄有它自己的tableview。
  • 此表有其自己的代表&數據源方法。

希望您能正確區分兩種桌面代理&數據源方法。

在選擇從搜索tableview中的任意單元格,你應該叫

[self.searchDisplayController setActive:NO animated:YES]; 

這將解散你的搜索結果表視圖,您導航到你的控制器視圖。

+0

thanx。很好的解釋 –

+0

我解決了我的兩個問題之前,你把這個,我說這是一個很好的解釋而已。 thanx,我爲你做了upvote.good work.thanx再次。 –

+0

非常感謝你! –

相關問題