需要 UINavigationController 的帮助
我有一个名为 CataloguesEtTarifsPDFViewController
的类,它显示 tableView。 现在,在这个类中,我想创建一个 UINavigationController
并设置 UINavigationController
这个类的根:
这是我所做的:
CataloguesEtTarifsPDFViewController.h
UINavigationController *navigationController;
在实现文件中
CataloguesEtTarifsPDFViewController.m
- (void)viewDidLoad
{
CataloguesEtTarifsPDFViewController *catalog =[[CataloguesEtTarifsPDFViewController alloc] init];
loadingView.hidden=YES;
navigationController = [[UINavigationController alloc] initWithRootViewController:catalog];
}
当我单击表格时我这样做:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewController *webViewController = [[WebViewController alloc] init];
[self.navigationController pushViewController:webViewController animated:YES];
[navigationController release];
}
但是当我运行并单击 tableView 时,没有任何反应...没有显示视图!我哪里出错了?
重要:我没有委托文件。只有 CataloguesEtTarifsPDFViewController.h
CataloguesEtTarifsPDFViewController.m
和 CataloguesEtTarifsPDFViewController.xib
。
编辑:
- (IBAction)showViewCataloguesEtTarifsPDF:(id)sender{
// Remove view to middleView
[mainMenuViewController removeViewsToMiddleView];
// create view controller
cataloguesEtTarifsPDFViewController = [[CataloguesEtTarifsPDFViewController alloc] init];
cataloguesEtTarifsPDFViewController.mainMenuViewController = mainMenuViewController;
// hide/show header button
[mainMenuViewController.headerViewController showMainMenuButton];
// highlight footer tabbar button
[mainMenuViewController.footerViewController.footerTabBar setSelectedItem:mainMenuViewController.footerViewController.footerTabBarItemMyAudi];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:cataloguesEtTarifsPDFViewController];
[self presentModalViewController:navigationController animated:YES];
}
I have a class called CataloguesEtTarifsPDFViewController
which displays a tableView.
Now, inside this class I wanna create a UINavigationController
and set the root of the UINavigationController
this class:
Here is what I did:
CataloguesEtTarifsPDFViewController.h
UINavigationController *navigationController;
in the implementation file
CataloguesEtTarifsPDFViewController.m
- (void)viewDidLoad
{
CataloguesEtTarifsPDFViewController *catalog =[[CataloguesEtTarifsPDFViewController alloc] init];
loadingView.hidden=YES;
navigationController = [[UINavigationController alloc] initWithRootViewController:catalog];
}
When I click on the table cell I do this:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
WebViewController *webViewController = [[WebViewController alloc] init];
[self.navigationController pushViewController:webViewController animated:YES];
[navigationController release];
}
But when I run and click on the tableView nothing happens...not view is showed up!!!Where am I going wrong?
IMPORTANT: I don't have a delegate file.Only CataloguesEtTarifsPDFViewController.h
CataloguesEtTarifsPDFViewController.m
and CataloguesEtTarifsPDFViewController.xib
.
EDIT:
- (IBAction)showViewCataloguesEtTarifsPDF:(id)sender{
// Remove view to middleView
[mainMenuViewController removeViewsToMiddleView];
// create view controller
cataloguesEtTarifsPDFViewController = [[CataloguesEtTarifsPDFViewController alloc] init];
cataloguesEtTarifsPDFViewController.mainMenuViewController = mainMenuViewController;
// hide/show header button
[mainMenuViewController.headerViewController showMainMenuButton];
// highlight footer tabbar button
[mainMenuViewController.footerViewController.footerTabBar setSelectedItem:mainMenuViewController.footerViewController.footerTabBarItemMyAudi];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:cataloguesEtTarifsPDFViewController];
[self presentModalViewController:navigationController animated:YES];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能应该阅读以下内容: http://www.iosdevnotes.com/2011/03/ uinavigationcontroller-教程/
或者这样: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457-CH1-SW1
或观看这个: http://peepcode.com/products/iphone-view-controllers-part-i
这将为您提供基础知识,您将有能力回答您的问题并解决您的问题代码:)
PS:您不必在视图控制器中显式创建和设置 UINavigationController。如果视图控制器嵌入在导航控制器中,则视图控制器实例的 navigationController 属性将自动找到它并返回它。
You should probably read this: http://www.iosdevnotes.com/2011/03/uinavigationcontroller-tutorial/
Or this: http://developer.apple.com/library/ios/#featuredarticles/ViewControllerPGforiPhoneOS/Introduction/Introduction.html#//apple_ref/doc/uid/TP40007457-CH1-SW1
Or watch this: http://peepcode.com/products/iphone-view-controllers-part-i
That'll give you the basics and you'll be well equipped to answer your question and fix your code :)
PS: You don't have to explicitly create and set a UINavigationController in your view controller. If the view controller is embedded within a navigation controller, the navigationController property of your view controller instance will automatically find it and return it.
您在 viewDidLoad 中所做的事情是错误的。
无论您在何处显示 CataloguesEtTarifsPDFViewController,都应该将其包装在 UINavigationController 中并显示 UINavigationController。
这将确保设置 UIViewController 的 navigationController 属性。
在 tableView:didSelectRowAtIndexPath: 方法中,您应该释放 webViewController 变量而不是 navigationController 属性。
What you're doing in viewDidLoad is wrong.
Wherever you are showing the CataloguesEtTarifsPDFViewController, you should wrap it in a UINavigationController there and show the UINavigationController instead.
This will make sure the navigationController property of UIViewController will be set.
In your tableView:didSelectRowAtIndexPath: method you should release the webViewController variable instead of the navigationController property.