将视图控制器推入navigationController时出现问题

时间:2011-09-20 07:39:20

标签: iphone xcode uitableview uinavigationcontroller

我需要一些帮助。在我的Iphone应用程序中,我做了类似这样的事情: 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];

        }

    }

请告诉我哪里出错了,因为这似乎不起作用。谢谢。

2 个答案:

答案 0 :(得分:0)

方法是使用第一个tableView作为其rootViewController的navigationController对象。在didSelectRowAtIndexPath:方法上,继续执行此操作。这将推送detailViewController。在rootViewController中,隐藏导航栏。

答案 1 :(得分:0)

从评论转到此处。

您应该将导航控制器添加到根视图,否则您将无法调用方法pushViewConroller:

例如,您可以通过以下方式创建根视图控制器:

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

例如,您可以通过以下方式推送导航控制器:

[self presentModalViewController:navController animated:YES];
相关问题