2016-06-20 76 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某些其他風格。

相關問題