没有调用UITableViewDelegate

时间:2017-07-03 05:50:14

标签: ios uitableview uisearchbar uisearchbardelegate

enter image description here

这里我在" TO"中使用了UIsearchBar。当用户搜索某些内容时,我使用UITableView显示搜索结果。 当用户从该结果表中选择一行时,它将转到详细信息页面。 但在这种情况下,当用户点击UITable View时,它不会触发UITableView Delegate,didSelectRowAtIndexPath。相反,关闭键盘。然后用户需要在解除键盘后再次点击桌面。 因此,每当他想从结果表中选择一行时,用户需要点击两次。任何人都可以帮我解决这个问题吗?

#pragma mark - UISearchBarDelegate
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    if ([self.delegate     respondsToSelector:@selector(showCalloutRouteDestinationView:)])
        [self.delegate showCalloutRouteDestinationView:(int)searchBar.tag];

    return YES;
}

- (BOOL)textFieldShouldEndEditing:(UISearchBar *)searchBar
{
    return YES;
}

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    if ([self.delegate       respondsToSelector:@selector(showSearchFromResult:andTag:)])
            [self.delegate showSearchFromResult:searchText andTag:(int)searchBar.tag];

}

这是我对didSelectRowAtIndexPath

的实现
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *location = self.searchByTextResults[indexPath.row];
    NSString *type = location[SERVER_CATEGORY];

    if  (indexPath.row == 0 && self.isTxtFrom){
        if ([self.delegate respondsToSelector:@selector(selectAmenity:context:)])
            [self.delegate selectMyLocation:self.currentLocation];

        return;
    }else{
        if ([self.delegate respondsToSelector:@selector(didSelectDataForRoute:andType:context:)])
            [self.delegate didSelectDataForRoute:(self.isTxtFrom ?     self.searchByTextResults[indexPath.row - 1]:   self.searchByTextResults[indexPath.row]) andType:type   context:self.locationContext];
    }
}

0 个答案:

没有答案