In my application I have a TableView full of cells. Everything works just fine -- When I tap on a cell, it calls tableView:DidSelectRowAtIndexPath:
right away and executes a segue, bringing me to the next screen. I also have a search bar, using UISearchDisplayController, allowing users to search through the items in the tableView. When I type some text into the search bar, the cells that match the search display in the table.
在我的应用程序中,我有一个满是单元格的表视图。一切正常——当我点击一个单元格时,它调用tableView:DidSelectRowAtIndexPath:立即执行一个segue,将我带到下一个屏幕。我还有一个搜索栏,使用UISearchDisplayController,允许用户搜索tableView中的项目。当我在搜索栏中输入一些文本时,与表中的搜索显示相匹配的单元格。
Now, my problem is when I tap on one of the cells displayed in this search results table... On one initial tap, the table view does not respond in any way. If the tap is held just briefly, the cell turns gray, as if it were selected, however tableView:DidSelectRowAtIndexPath:
is still not called, and the cell turns back to normal after releasing the tap. But if I do a long press for a few seconds, then tableView:DidSelectRowAtIndexPath:
is finally called, and I am brought to the correct screen.
现在,我的问题是当我点击搜索结果表中显示的一个单元格时……在一次初始点击中,表视图不会以任何方式响应。如果只是简单地按住tap,单元格就会变为灰色,就好像它被选中了一样,但是仍然没有调用tableView:DidSelectRowAtIndexPath:,并且单元格在释放tap后返回到正常状态。但是如果我做了几秒钟的长按,那么tableView:DidSelectRowAtIndexPath:最终被调用,我被带到正确的屏幕上。
Has anyone encountered this problem before? As far as I know I have implemented my UISearchDisplayController the same exact way as I always have, and have never had this problem.
以前有人遇到过这个问题吗?就我所知,我实现UISearchDisplayController的方式和以前一样,从来没有遇到过这个问题。
Thank You, and let me know if I can give any additional information that may be helpful
谢谢,如果我能提供任何可能有帮助的信息,请告诉我
EDIT
编辑
I am not certain wherein the problem lies exactly, so I'm not sure which methods to show, but here is some code... I am bringing up the search bar upon clicking an icon in the UINavigationBar, then removing it from the superview once the editing has finished.
我不确定问题到底出在哪里,所以我不确定应该显示哪些方法,但是这里有一些代码……单击UINavigationBar中的图标时,我将打开搜索栏,然后在编辑完成后将其从超视图中删除。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
NSArray *contentArray;
if (tableView == self.tableView) {
contentArray = self.postArray;
} else if (tableView == self.searchDisplayController.searchResultsTableView) {
contentArray = self.searchResults;
}
// This is pretty hackish, but it wasn't working before for some reason. So I send the PFObject I want as the sender
[self performSegueWithIdentifier:@"ShowPostDetails" sender:contentArray[indexPath.row]];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"PostCell";
PostTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (!cell) {
cell = [[PostTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
[self updateSubviewsForCell:cell inTableView:tableView atIndexPath:indexPath];
/*
if (tableView == self.searchDisplayController.searchResultsTableView) {
[cell addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cellTapped:)]];
} */
return cell;
}
#pragma mark - Search Bar Delegate
- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
NSPredicate *resultPredicate = [NSPredicate predicateWithFormat:@"text contains[c] %@", searchText];
self.searchResults = [self.postArray filteredArrayUsingPredicate:resultPredicate];
}
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{
[self filterContentForSearchText:searchString
scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
objectAtIndex:[self.searchDisplayController.searchBar
selectedScopeButtonIndex]]];
return YES;
}
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
{
[self.view addSubview:self.searchDisplayController.searchBar];
self.searchDisplayController.searchBar.center = CGPointMake(self.view.window.center.x, 42);
}
- (void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller
{
[self.searchDisplayController.searchBar removeFromSuperview];
}
1 个解决方案
#1
1
I found my problem...
我发现我的问题…
The specific view controller that was experiencing this problem is subclassed from the view controller containing these delegate methods, and contains a UITextField for entering information. I watch for a keyboardDidAppear notification, and when it appears I add a UITapGestureRecognizer to the view to close the keyboard by resigning first responder of the UITextField when the view is tapped. When I added this I had not yet implemented the search feature, so I knew the only reason the keyboard would pop up is for the UITextField. The problem is that this extra TapGestureRecognizer added when the keyboard popped up for the search bar prevented the TapGestureRecognizer built into the UITableView cell from firing. I was looking in the wrong spot for the problem. To fix the problem I simply made a check that the UITextField is indeed the first responder before adding the gesture recognizer. Now all works as it is supposed to.
遇到此问题的特定视图控制器从包含这些委托方法的视图控制器中子类化,并包含用于输入信息的UITextField。我观察一个keyboardDidAppear通知,当它出现时,我向视图添加一个UITapGestureRecognizer,当视图被单击时,通过放弃UITextField的第一个响应器来关闭键盘。当我添加这个时,我还没有实现搜索功能,所以我知道弹出键盘的唯一原因是UITextField。问题是,当键盘弹出到搜索栏时,这个额外的TapGestureRecognizer会阻止内置在UITableView单元格中的tapgesturerecnizer触发。我找错了地方。为了解决这个问题,我只是在添加手势识别器之前检查UITextField是否确实是第一个响应程序。现在一切都按预期运行。
So for anyone else experiencing a similar problem, I'd say go back and make sure you don't have any other UIGestureRecognizers that might be conflicting with the gesture recognizers of your tableView.
对于其他遇到类似问题的人,我建议你回去确保你没有任何其他的UIGestureRecognizers它们可能与你的tableView的手势识别器有冲突。
Thanks to everyone who commented. Helped lead me to where the problem was.
感谢所有评论的人。帮助我找到问题所在。
#1
1
I found my problem...
我发现我的问题…
The specific view controller that was experiencing this problem is subclassed from the view controller containing these delegate methods, and contains a UITextField for entering information. I watch for a keyboardDidAppear notification, and when it appears I add a UITapGestureRecognizer to the view to close the keyboard by resigning first responder of the UITextField when the view is tapped. When I added this I had not yet implemented the search feature, so I knew the only reason the keyboard would pop up is for the UITextField. The problem is that this extra TapGestureRecognizer added when the keyboard popped up for the search bar prevented the TapGestureRecognizer built into the UITableView cell from firing. I was looking in the wrong spot for the problem. To fix the problem I simply made a check that the UITextField is indeed the first responder before adding the gesture recognizer. Now all works as it is supposed to.
遇到此问题的特定视图控制器从包含这些委托方法的视图控制器中子类化,并包含用于输入信息的UITextField。我观察一个keyboardDidAppear通知,当它出现时,我向视图添加一个UITapGestureRecognizer,当视图被单击时,通过放弃UITextField的第一个响应器来关闭键盘。当我添加这个时,我还没有实现搜索功能,所以我知道弹出键盘的唯一原因是UITextField。问题是,当键盘弹出到搜索栏时,这个额外的TapGestureRecognizer会阻止内置在UITableView单元格中的tapgesturerecnizer触发。我找错了地方。为了解决这个问题,我只是在添加手势识别器之前检查UITextField是否确实是第一个响应程序。现在一切都按预期运行。
So for anyone else experiencing a similar problem, I'd say go back and make sure you don't have any other UIGestureRecognizers that might be conflicting with the gesture recognizers of your tableView.
对于其他遇到类似问题的人,我建议你回去确保你没有任何其他的UIGestureRecognizers它们可能与你的tableView的手势识别器有冲突。
Thanks to everyone who commented. Helped lead me to where the problem was.
感谢所有评论的人。帮助我找到问题所在。