簡體   English   中英

將視圖控制器推入NavigationController時出現問題

[英]Problem in pushing a view controller into a navigationController

我需要協助。 在我的Iphone App中,我做了這樣的事情: 在此處輸入圖片說明

選擇“距離”后,我需要顯示另一個視圖,如下所示: 在此處輸入圖片說明

這是我的做法:

在頭文件中

@interface RecherchePartenaireViewController : UIViewController <UINavigationControllerDelegate>
{
    UINavigationController *navigationController;
    UITableView *tableViewRecherchePartenaire;
    RecherchePartenaireTypePartenaireViewController *recherchePartenaireTypePartenaireViewController;
    RecherchePartenaireDistanceViewController *recherchePartenaireDistanceViewController;
}
@property (nonatomic, retain) IBOutlet UINavigationController *navigationController;
@property (nonatomic, retain) IBOutlet UITableView *tableViewRecherchePartenaire;
@property (nonatomic, retain) IBOutlet  RecherchePartenaireTypePartenaireViewController *recherchePartenaireTypePartenaireViewController;
@property (nonatomic, retain) IBOutlet RecherchePartenaireDistanceViewController *recherchePartenaireDistanceViewController;

@end

在實施文件中

- (void)viewDidLoad
{

    listData = [[NSMutableArray alloc] initWithObjects:@"Type de Partenaire", @"Code postal", @"Ville",@"Distance",@"Nom du Partenaire",@"Audi R8 uniquement",nil];
    NSLog(@"hey %@",listData);
    tableViewRecherchePartenaire.backgroundColor = [UIColor clearColor];   
    navigationController=[[UINavigationController alloc] init];

    CGRect newRect = navigationController.view.frame;
    newRect.size.height -= [UIScreen mainScreen].applicationFrame.origin.y;
    [navigationController.view setFrame:newRect];
    [navigationController setNavigationBarHidden:YES];
    [super viewDidLoad];
}

當選擇表的第三行時,我這樣做:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
    {
        if (indexPath.row==3){
            NSLog(@"RecherchePartenaireDistanceViewController..."); 
            recherchePartenaireDistanceViewController = [[RecherchePartenaireDistanceViewController alloc]  init];
          recherchePartenaireDistanceViewController.recherchePartenaireViewController=self;

            [self.navigationController pushViewController:recherchePartenaireDistanceViewController animated:YES];

        }

    }

請告訴我我要去哪里錯了,因為這似乎行不通。謝謝。

該方法將具有一個帶有第一個tableView作為其rootViewController的navigationController對象。 在didSelectRowAtIndexPath:方法上,像現在一樣繼續進行。 這將推動detailViewController。 然后在您的rootViewController中,隱藏導航欄。

從評論移到這里。

您應該將導航控制器添加到根視圖中,否則將無法調用方法pushViewConroller:

例如,您可以通過以下方式創建根視圖控制器:

RootViewController *controller = [[RootViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[controller release];

例如,您可以按以下方式推送導航控制器:

[self presentModalViewController:navController animated:YES];

暫無
暫無

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

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