【问题标题】:Problem in pushing a view controller into a navigationController将视图控制器推入导航控制器的问题
【发布时间】:2011-09-20 07:39:19
【问题描述】:

我需要一些帮助。在我的 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];

        }

    }

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

【问题讨论】:

  • 我没有在父对象中看到导航控制器...
  • 如果我把这个:[self.view addSubview:navigationController.view];在 viewDidLoad 中,tableview 未选中...在 tableview 上我有一些要更改的文本字段,并且使用此行,键盘没有出现...那么,我该怎么办?
  • 可以这样推送:[self presentModalViewController: recherchePartenaireDistanceViewController animated:YES];
  • 我这样视图是从下往上看的。 ..我希望视图从右到左显示,而不是从下到上..我该怎么做?
  • 检查UIModalTransitionStyle modalTransitionStyle...但是没有这种风格。

标签: iphone xcode uitableview uinavigationcontroller


【解决方案1】:

该方法是使用第一个 tableView 作为其 rootViewController 的 navigationController 对象。在 didSelectRowAtIndexPath: 方法上,像现在一样继续。这将推动 detailViewController。在你的 rootViewController 中,隐藏导航栏。

【讨论】:

    【解决方案2】:

    从 cmets 移动到这里。

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

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

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

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

    [self presentModalViewController:navController animated:YES];
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-14
      • 2014-01-11
      • 1970-01-01
      • 2017-06-25
      • 2016-04-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多