将视图控制器推入导航控制器时出现问题
我需要一些帮助。在我的 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 :
.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
方法是使用第一个 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.
从注释移至此处。
您应该将导航控制器添加到根视图,否则您将无法调用方法
pushViewConroller:
。例如,您可以通过以下方式创建根视图控制器:
您可以通过以下方式推送导航控制器:
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:
You can push navigation controller, for example, in a such way: