2011-02-17 37 views
1

我在這裏得到了一個問題。每當用戶選擇任何行,我想調用該方法searchBarCancelButtonClicked執行[searchBar resignFirstResponder];我怎樣才能做到這一點?在另一個方法中調用searchBarCancelButtonClicked方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    NSString *KeyCor; 
    NSString *YKeyCor; 
    NSString *DesName; 
    Service *aService; 

    aService = [appDelegate.blocks objectAtIndex:indexPath.row]; 

    KeyCor=[aService xcoordinate]; 
    YKeyCor=[aService ycoordinate]; 
    DesName=[aService name]; 

    Service *s = [[Service alloc] initWithLat:YKeyCor andLong:KeyCor andName:DesName]; 
    MapViewController *mvController = (MapViewController *)[MapViewController sharedInstance]; 
    mvController.view.alpha = 1; 

    //[self.navigationController pushViewController:mvController animated:YES]; 
    [mvController showMarkingOnMap:s]; 


    //self.searchBarCancelButtonCLicked; <--- fail 

    /// 
} 

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar 

{ 
    sBar.showsCancelButton = NO; 
    [tableData removeAllObjects]; 
    [tableData addObjectsFromArray:dataSource]; 

    [searchBar resignFirstResponder]; 

    sBar.text = @""; 

    [myTableView removeFromSuperview]; 

} 

回答

2
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 

    ... 

    [self searchBarCancelButtonClicked:whateverYouNamedYourSearchbar]; 
} 
相關問題