mardi 21 juin 2016

Pushing View Controller from Child View Controller


I am developing an application where there is a container view and I am attempting to push it into another view controller from the parent. When I try pushing the navigation bar stays the same of the parent view controller rather than turning into the navigation bar of the newly pushed controller. Here is a animation of what is going wrong. enter image description here How would I make the navigation bar change to the new view controller. (On a side-note the keyboard doesnt seem to dismiss either)

Parent 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];
}

Child 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];
    }
}

New 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;
}

Aucun commentaire:

Enregistrer un commentaire