Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios SearchDisplayController表视图序列问题_Ios_Objective C_Uitableview_Segue_Uisearchdisplaycontroller - Fatal编程技术网

Ios SearchDisplayController表视图序列问题

Ios SearchDisplayController表视图序列问题,ios,objective-c,uitableview,segue,uisearchdisplaycontroller,Ios,Objective C,Uitableview,Segue,Uisearchdisplaycontroller,我正在尝试将searchDisplayController放入我的tableviewController中。它似乎工作得很好,但当我单击tableViewCell并尝试切换到detailViewController时,应用程序崩溃了 只有当我不尝试执行搜索时,它才会崩溃。如果我点击其中一个过滤结果,它会将我与detailViewController隔离开来。你知道为什么这可能不起作用吗?谢谢大家! - (void)tableView:(UITableView *)tableView didSel

我正在尝试将searchDisplayController放入我的tableviewController中。它似乎工作得很好,但当我单击tableViewCell并尝试切换到detailViewController时,应用程序崩溃了

只有当我不尝试执行搜索时,它才会崩溃。如果我点击其中一个过滤结果,它会将我与detailViewController隔离开来。你知道为什么这可能不起作用吗?谢谢大家!

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath 
*)indexPath {
    [self performSegueWithIdentifier:@"showBusinessDetails" sender:indexPath];
}

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {

    if ([[segue identifier] isEqualToString:@"showBusinessDetails"]) {
        ProfileViewController *destination = [segue destinationViewController];
        NSIndexPath * indexPath = (NSIndexPath*)sender;

        if (self.tableView == self.searchDisplayController.searchResultsTableView) {
            destination.title = [[businesses objectAtIndex:indexPath.row] 
            valueForKey:@"name"];
            destination.businessDetails = [businesses objectAtIndex:indexPath.row];
        }
        else {
            destination.title = [[filteredBusinesses objectAtIndex:indexPath.row] 
            valueForKey:@"name"];
            destination.businessDetails = [filteredBusinesses 
            objectAtIndex:indexPath.row];
        }
    }
}

看起来你的if语句倒过来了。如果表视图是searchResultsTableView,那么您应该从FilteredBusiness(非业务)获取业务详细信息,不是吗?

您应该询问一个类似的问题,即在
UITableViewController
委托方法中,哪一个是当前活动的表视图,
tableView:didSelectRowAtIndexPath:

正如您所写,此委托方法只能响应
self.tableView
,但是您也希望它响应
self.searchDisplayController.searchResultsTableView

要使其能够响应self.searchDisplayController.searchResultsTableView,您应该包含类似以下内容的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        UIViewController *destinationVC = nil;
        SegueList *segueToList = nil;

        NSString *mainStoryboard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIMainStoryboardFile"];
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:mainStoryboard bundle:nil];

        if ([self.entity isEqualToString:self.localisedEntityDocument]) {
            destinationVC = [storyboard instantiateViewControllerWithIdentifier:@"id_ViewControllerExample1"]; //insert appropriate "ID"
            segueToList = [[SegueList alloc] initWithIdentifier:@"segueView"
                                                         source:self
                                                    destination:destinationVC];

        } else if ([self.entity isEqualToString:self.localisedEntityTransmittal]) {
            destinationVC = [storyboard instantiateViewControllerWithIdentifier:@"id_ViewControllerExample2"]; //insert appropriate "ID"
            segueToList = [[SegueList alloc] initWithIdentifier:@"segueView"
                                                         source:self
                                                    destination:destinationVC];

        } else {
            //error logging
        }
        UITableViewCell *cellSegue = [tableView cellForRowAtIndexPath:indexPath];
        [self prepareForSegue:segueToList sender:cellSegue];
        [segueToList perform];
    } else {
        //Probably nothing here if you are using a storyboard segues.
    }
}
#pragma mark - CUSTOM SEGUE
#pragma mark

////////////////////////////////////////////////////////////
/// Subclass of UIStoryboardSegue must override -perform ///
////////////////////////////////////////////////////////////
@interface SegueList : UIStoryboardSegue

@end

@implementation SegueList

- (void)perform {
    DD_TVC_List *sourceViewController = self.sourceViewController;
    [sourceViewController.navigationController pushViewController:self.destinationViewController animated:YES];
}

@end
////////////////////////////////////////////////////////////
///         END of subclass of UIStoryboardSegue         ///
////////////////////////////////////////////////////////////

@interface //normal TVC implementation file
请注意,您需要在序列图像板中为目标视图控制器输入(或应用)视图控制器ID

您还需要编写自定义序列。我更喜欢把我的放在TVC类的顶端,它们是必需的,使用类似于下面的代码

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        UIViewController *destinationVC = nil;
        SegueList *segueToList = nil;

        NSString *mainStoryboard = [[NSBundle mainBundle] objectForInfoDictionaryKey:@"UIMainStoryboardFile"];
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:mainStoryboard bundle:nil];

        if ([self.entity isEqualToString:self.localisedEntityDocument]) {
            destinationVC = [storyboard instantiateViewControllerWithIdentifier:@"id_ViewControllerExample1"]; //insert appropriate "ID"
            segueToList = [[SegueList alloc] initWithIdentifier:@"segueView"
                                                         source:self
                                                    destination:destinationVC];

        } else if ([self.entity isEqualToString:self.localisedEntityTransmittal]) {
            destinationVC = [storyboard instantiateViewControllerWithIdentifier:@"id_ViewControllerExample2"]; //insert appropriate "ID"
            segueToList = [[SegueList alloc] initWithIdentifier:@"segueView"
                                                         source:self
                                                    destination:destinationVC];

        } else {
            //error logging
        }
        UITableViewCell *cellSegue = [tableView cellForRowAtIndexPath:indexPath];
        [self prepareForSegue:segueToList sender:cellSegue];
        [segueToList perform];
    } else {
        //Probably nothing here if you are using a storyboard segues.
    }
}
#pragma mark - CUSTOM SEGUE
#pragma mark

////////////////////////////////////////////////////////////
/// Subclass of UIStoryboardSegue must override -perform ///
////////////////////////////////////////////////////////////
@interface SegueList : UIStoryboardSegue

@end

@implementation SegueList

- (void)perform {
    DD_TVC_List *sourceViewController = self.sourceViewController;
    [sourceViewController.navigationController pushViewController:self.destinationViewController animated:YES];
}

@end
////////////////////////////////////////////////////////////
///         END of subclass of UIStoryboardSegue         ///
////////////////////////////////////////////////////////////

@interface //normal TVC implementation file

最后,在TVC
prepareForSegue
方法中包含相应的代码,以响应委派方法中的segue标识符(在我的示例code
segueView
中),
tableView:didSelectRowAtIndexPath:

谢谢,你说得对,但实际上,我的代码似乎没有区分搜索栏是否有内容。if语句每次都返回false。您是以编程方式添加
UISearchDisplayController
还是使用情节提要?