简体   繁体   中英

Problem in pushing a view controller into a navigationController

I need some help. In my Iphone App I have done something like this : 在此处输入图片说明 .

When Distance is selected, I need to show up another view like this: 在此处输入图片说明

Here is how I did it:

in the header file

@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

in the implementation file

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

When the third row of the table is selected I do this:

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

        }

    }

Please tell me where am I going wrong cause this doesn't seem to work.Thank you.

The approach would be to have a navigationController object with the first tableView as its rootViewController. On the didSelectRowAtIndexPath: method proceed as you do right now. That will push the detailViewController. And in your rootViewController, hide the navigation bar.

Moving from comments to here.

You should add navigation controller to your root view or you won't be able to call method pushViewConroller: .

For example, you can create root view controller in such manner:

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

You can push navigation controller, for example, in a such way:

[self presentModalViewController:navController animated:YES];

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM