문제

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!

올바른 솔루션이 없습니다

다른 팁

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top