从子视图控制器推送视图控制器

时间:2016-06-20 23:31:03

标签: ios objective-c iphone uinavigationcontroller containers

我正在开发一个应用程序,其中有一个容器视图,我试图将它从父级推送到另一个视图控制器。当我尝试按下导航栏时保持与父视图控制器相同,而不是转到新推送的控制器的导航栏。这是一个出错的动画。 enter image description here 如何将导航栏更改为新的视图控制器。 (另一方面,键盘似乎也没有解雇)

家长VC

- (UIViewController *)carbonTabSwipeNavigation:(CarbonTabSwipeNavigation *)carbonTabSwipeNavigation
                         viewControllerAtIndex:(NSUInteger)index {
    if(index == 0){
        SearchChildVC *svc = [[SearchChildVC alloc] init];
        svc.results = nil;
        [self searchTop:_searchBar.text];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"reload_data" object:self];
        return svc;
    }else if(index == 1){
        SearchChildVC *svc = [[SearchChildVC alloc] init];
        svc.results = nil;
        [self searchPeople:_searchBar.text];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"reload_data" object:self];
        return svc;
    }else if(index == 2){
        SearchChildVC *svc = [[SearchChildVC alloc] init];
        svc.results = nil;
        [self searchOrganizations:_searchBar.text];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"reload_data" object:self];
        return svc;
    }
    return [[SearchChildVC alloc] init];
}

儿童VC

- (void)tableView: (UITableView *) tableView didSelectRowAtIndexPath: (NSIndexPath *) indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    PFObject *data = self.results[indexPath.row];
    if (data[@"fullName"]) {
        // User Cell
        [self resignFirstResponder];
        ForeignProfileVC *fvc = [[ForeignProfileVC alloc] init];
        //fvc.userId = ;
        [self.navigationController pushViewController:fvc animated:YES];
    }else{
        // Organization Cell
        [self resignFirstResponder];
        OrganizationViewController *ovc = [[OrganizationViewController alloc] init];
        ovc.object = (NSDictionary *)data;
        [self.navigationController pushViewController:ovc animated:YES];
    }
}

新VC

-(void)setupUI {
    self.view.backgroundColor = [UIColor whiteColor];
    NSString *organizationTitle = [self.object objectForKey:@"Name"];
    [self.navigationItem setTitle:organizationTitle];
    self.view.backgroundColor = [UIColor whiteColor];
    [self.navigationController.navigationBar setTitleTextAttributes:
     @{NSForegroundColorAttributeName:[UIColor whiteColor],
       NSFontAttributeName:[UIFont fontWithName:@"OpenSans-Semibold" size:18]}];

    UIButton *barButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [barButton setTitle:@"" forState:UIControlStateNormal];
    [barButton setBackgroundImage:[UIImage imageNamed:@"closeIcon"] forState:UIControlStateNormal];
    [barButton addTarget:self action:@selector(didTapClose:) forControlEvents:UIControlEventTouchUpInside];
    barButton.frame = CGRectMake(0.0f, 0.0f, 15.0f, 15.0f);
    UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:barButton];
    self.navigationItem.leftBarButtonItem = barButtonItem;

    UIButton *postButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [postButton setTitle:@"" forState:UIControlStateNormal];
    [postButton setBackgroundImage:[UIImage imageNamed:@"gearIcon"] forState:UIControlStateNormal];
    [postButton addTarget:self action:@selector(didTapGear:) forControlEvents:UIControlEventTouchUpInside];
    postButton.frame = CGRectMake(0.0f, 0.0f, 18.0f, 18.0f);
    UIBarButtonItem *postButtonItem = [[UIBarButtonItem alloc] initWithCustomView:postButton];
    self.navigationItem.rightBarButtonItem = postButtonItem;
}

1 个答案:

答案 0 :(得分:3)

pushViewController将重复使用相同的导航控制器。您可以执行将显示新视图控制器的presentViewController,或者自己处理搜索栏的更改。例如,在新视图中,控制器将显示类似于将searchbar hidden / set navigationbar设置为其他样式的内容。