从搜索显示控制器的表视图推送详细信息控制器

发布于 2024-12-23 12:21:16 字数 91 浏览 1 评论 0原文

我在我的应用程序中实现了搜索选项,但是当我搜索某些内容时,我无法从搜索显示控制器的表视图中推送详细信息控制器。
有办法做到这一点吗?

太感谢了!

I implemented a search option in my app but when I search something, I can't push a detail controller from the search display controller's table view.
Is there a way to do that?

Thank you so much!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

束缚m 2024-12-30 12:21:16

我们假设您在 UIViewController 中有一个名为 SearchViewControllerUISearchBarDelegate 方法。要推送 (DetailViewController*) dvc,请在 SearchViewController 中实现以下方法:

#pragma mark - Search bar delegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    if (searchTextMatchedSomeTarget) {
        textForDetailView = searchText;
        [self performSegueWithIdentifier:seguePushDetailView sender:self];
    }
}

#pragma mark - View lifecycle
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:seguePushDetailView]) {
        dvc = (DetailViewController *)[segue destinationViewController];
        dvc.delegate = (id)self;
        dvc.searchText = textForDetailView;
    }
}

#pragma mark - Detail view controller protocol delegate
- (void)DetailViewControllerDidFinish:(DetailViewController *)controller
{
    NSString *somethingBackFromDetailView = controller.backToSearchView;
}

UIDetailViewController 声明一个带有“did”的协议 finish”方法和您喜欢的任何类型的属性,既可以从 SearchViewController 接收数据,也可以在任何详细处理后发回任何数据。通过将控件从 UISearchViewController 拖动到 UIDetailViewController,可以在 Xcode IB 中添加 Segue。 注意: Segue 源和目标是视图控制器本身。这样,它们就可以以编程方式调用,而不是在点击事件上自动调用。

We'll assume you have a UISearchBarDelegate method in a UIViewController called SearchViewController. To push (DetailViewController*) dvc, implement these methods in SearchViewController:

#pragma mark - Search bar delegate
- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    if (searchTextMatchedSomeTarget) {
        textForDetailView = searchText;
        [self performSegueWithIdentifier:seguePushDetailView sender:self];
    }
}

#pragma mark - View lifecycle
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:seguePushDetailView]) {
        dvc = (DetailViewController *)[segue destinationViewController];
        dvc.delegate = (id)self;
        dvc.searchText = textForDetailView;
    }
}

#pragma mark - Detail view controller protocol delegate
- (void)DetailViewControllerDidFinish:(DetailViewController *)controller
{
    NSString *somethingBackFromDetailView = controller.backToSearchView;
}

UIDetailViewController declares a protocol with the "did finish" method and properties of whatever type you like, both to receive data from SearchViewController and to send back any data after any detail processing. The segue is added in Xcode IB by control dragging from UISearchViewController to UIDetailViewController. NB: the segue source and destination are the view controllers themselves. That way they can be invoked programmatically as opposed to automatic invocation on a tap event.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文