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

发布于 2024-12-05 14:23:36 字数 2553 浏览 0 评论 0原文

我需要一些帮助。在我的 iPhone 应用程序中我做了这样的事情: 输入图片此处描述

选择“距离”时,我需要显示另一个视图,如下所示:在此处输入图像描述

这是我的做法:

在头文件中

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

        }

    }

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

I need some help. In my Iphone App I have done something like this :
enter image description here

.

When Distance is selected, I need to show up another view like this:enter image description here

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

还如梦归 2024-12-12 14:23:36

方法是使用第一个 tableView 作为 rootViewController 的 navigationController 对象。在 didSelectRowAtIndexPath: 方法上,按照您现在的操作进行操作。这将推动detailViewController。在 rootViewController 中,隐藏导航栏。

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.

绅士风度i 2024-12-12 14:23:36

从注释移至此处。

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

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

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

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

[self presentModalViewController:navController animated:YES];

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];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文