2016-06-20 188 views
0

我正在开发一个应用程序,其中有一个容器视图,我试图将它从父级推入另一个视图控制器。当我尝试推动导航栏保持与父视图控制器相同,而不是转入新推控制器的导航栏。这是一个错误的动画。 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; 
} 

回答

2

pushViewController将重用相同的导航控制器。您可以执行presentViewController这将显示一个新的视图控制器,或自己处理您的搜索栏的更改。例如,在新的视图中,控制器会出现类似于设置searchbar隐藏/设置navigationbar某些其他风格。

相关问题