簡體   English   中英

從子視圖控制器推送視圖控制器

[英]Pushing View Controller from Child View Controller

我正在開發一個有容器視圖的應用程序,並試圖將其從父級推送到另一個視圖控制器中。 當我嘗試按下時,導航欄保持與父視圖控制器相同,而不是變成新按下的控制器的導航欄。 這是發生問題的動畫。 在此處輸入圖片說明 如何將導航欄更改為新的視圖控制器。 (在旁注中,鍵盤似乎也沒有關閉)

家長風投

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

兒童風投

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

pushViewController將重用相同的導航控制器。 您可以執行presentViewController來呈現新的視圖控制器,也可以自己處理搜索欄的更改。 例如,在新的視圖控制器中將出現類似將搜索searchbar設置為隱藏/將navigationbar searchbar設置為其他樣式的操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM