在另一个方法中调用searchBarCancelButtonClicked方法

时间:2011-02-17 02:02:22

标签: iphone objective-c

我在这里有个问题。每当用户选择任何一行时,我想调用该方法searchBarCancelButtonClicked来执行[searchBar resignFirstResponder];我怎么能这样做?

- (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];

}

1 个答案:

答案 0 :(得分:3)

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

   ...

   [self searchBarCancelButtonClicked:whateverYouNamedYourSearchbar];
}