2016-01-18 56 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

非常感谢你! –

相关问题