2011-09-20 258 views
0

我需要一些幫助。在我的Iphone App中,我做了這樣的事情: http://i56.tinypic.com/10zn43p.png將視圖控制器推入導航控制器的問題

當選擇了距離,我需要出示了這樣的另一種觀點認爲:http://i51.tinypic.com/vzga6h.png

這是我如何做的:

在頭文件

@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]; 

     } 

    } 

請告訴我,我要去哪裏錯了導致這種似乎沒有work.Thank你不會。

+0

我沒有看到導航控制器父對象... – Nekto

+0

如果我把這個:[self.view addSubview:navigationController.view];在viewDidLoad中,tableview被取消選中...並且在tableview上我有一些我想要改變的文本框,並且在這一行中,鍵盤不會出現......所以我應該怎麼做? – Gabrielle

+0

你可以用這種方式推送:'[self presentModalViewController:recherchePartenaireDistanceViewController animated:YES];' – Nekto

回答

0

該方法是將一個帶有第一個tableView的navigationController對象作爲它的rootViewController。在didSelectRowAtIndexPath:方法上按照現在的方式繼續。這將推動detailViewController。並在你的rootViewController中,隱藏導航欄。

0

從評論移到這裏。

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

例如,你可以以這種方式創建根視圖控制器:

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

可以推導航控制器,例如,以這樣的方式:

[self presentModalViewController:navController animated:YES]; 
相關問題