将视图控制器推入导航控制器的问题
问题描述:
我需要一些帮助。在我的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你不会。
答
该方法是将一个带有第一个tableView的navigationController对象作为它的rootViewController。在didSelectRowAtIndexPath:方法上按照现在的方式继续。这将推动detailViewController。并在你的rootViewController中,隐藏导航栏。
答
从评论移到这里。
您应该将导航控制器添加到您的根视图,否则您将无法调用方法pushViewConroller:
。
例如,你可以以这种方式创建根视图控制器:
RootViewController *controller = [[RootViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
[controller release];
可以推导航控制器,例如,以这样的方式:
[self presentModalViewController:navController animated:YES];
我没有看到导航控制器父对象... – Nekto
如果我把这个:[self.view addSubview:navigationController.view];在viewDidLoad中,tableview被取消选中...并且在tableview上我有一些我想要改变的文本框,并且在这一行中,键盘不会出现......所以我应该怎么做? – Gabrielle
你可以用这种方式推送:'[self presentModalViewController:recherchePartenaireDistanceViewController animated:YES];' – Nekto