【问题标题】:Pushing View Controller from Child View Controller从子视图控制器推送视图控制器
【发布时间】:2016-10-22 08:23:00
【问题描述】:

我正在开发一个应用程序,其中有一个容器视图,并且我试图将它从父级推送到另一个视图控制器中。当我尝试推送导航栏时,它与父视图控制器保持不变,而不是变成新推送控制器的导航栏。这是出现问题的动画。 我如何将导航栏更改为新的视图控制器。 (在旁注中,键盘似乎也没有消失)

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

新风投

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

【问题讨论】:

    标签: ios objective-c iphone uinavigationcontroller containers


    【解决方案1】:

    pushViewController 将重用相同的导航控制器。您可以使用presentViewController 来显示一个新的视图控制器,也可以自己处理搜索栏的更改。例如,在新的视图控制器中会出现类似 set searchbar hidden/ set navigationbar 到其他样式的操作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多