当 searchDisplayController 处于活动状态时访问数据
我的 iPhone 应用程序使用 Core Data、UISearchBar、UISearchDisplayController、UITableView 和 UIActionSheet。当没有执行搜索时,我可以确定用户选择了哪一行,但是如果搜索处于活动状态并且用户选择了特定行,那么如何确定用户选择了哪一行?
示例:当 NO SEARCH 处于活动状态时,以下代码可以正常工作:
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
Event *event = (Event *)[[self fetchedResultsController] objectAtIndexPath:selectedIndexPath];
[self showURL:[NSURL URLWithString:event.siteSite] withTitle:@""];
但是,如果我使用上述方法确定相应的“event.siteSite”或 URL,则 URL 为 NULL,而 [self.searchDisplayController isActive] 等于 为真。
My iPhone app is using Core Data, UISearchBar, UISearchDisplayController, UITableView and UIActionSheet. When no search is being performed, I can determine which row was selected by the user, but if a search is active and selection made by the user of a specific row, how does one determine what row was selected by the user?
Example: The following code works without error when NO SEARCH is ACTIVE:
- (void)actionSheet:(UIActionSheet *)actionSheet willDismissWithButtonIndex:(NSInteger)buttonIndex {
NSIndexPath *selectedIndexPath = [self.tableView indexPathForSelectedRow];
Event *event = (Event *)[[self fetchedResultsController] objectAtIndexPath:selectedIndexPath];
[self showURL:[NSURL URLWithString:event.siteSite] withTitle:@""];
but, the URL is NULL if I use the above method to determine the corresponding "event.siteSite" or URL, while [self.searchDisplayController isActive]
equates
to TRUE.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您使用
UISearchDisplayController
时,您会在第一个表视图上叠加第二个表视图。您必须查询该表视图以找出选择了哪一行。请参阅 UISearchDisplayController 类参考细节。
When you use a
UISearchDisplayController
you get a second tableview super imposed on the first. It is that tabelview you have to query to find out which row was selected.See the UISearchDisplayController Class Reference for details.