Programmatically add UINavigationController in UIViewController(以编程方式在 UIViewController 中添加 UINavigationController)
问题描述
我目前的视图设置如下:
@interface BlogViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>{UITableView *mainTableView;}@property (nonatomic, 保留) UITableView *mainTableView;如您所见,它内部有一个 UITableView,我可以将所有数据加载到其中.但是,当我调用以下函数时:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {SingleBlogViewController *viewController = [[SingleBlogViewController alloc] init];[self.navigationController pushViewController:viewController Animation:YES];//[self presentModalViewController:viewController Animation:YES];[viewController 发布];}什么都没有发生.出于某种原因,我的 UIViewController 内部的 UITableView 没有推送视图.这是因为它不是 UITableViewController 吗?我试着改成那个,还是不行.
我错过了什么吗?
我找到了这篇博文有助于展示如何在没有 Interface Builder 的情况下以编程方式创建和使用 UINavigationController.
我希望文档和教程能够向我强调一些事情:
当您创建
UINavigationController时,您会免费获得一个 UIView 和 UINavigationBar(即您不需要单独添加它们并弄清楚如何将它们连接在一起).您将
myUINavigationController.view属性添加为主"视图,然后将UIViewController推送/弹出到 UINavigationController 上,它们将自动显示为在myUINavigationController.viewUIView 中可见.当你将
UIViewController推送到UINavigationController上时,UIViewController.navigationController会被填充.如果你没有推送导航控制器上的视图,我猜该属性是空的.以编程方式将按钮添加到
UINavigationBar的时间/地点不是您构建UINavigationController的时间和地点,而是由单个UIViewControllers 当你推送到UINavigationController时加载它们.我只需要在第一个
viewDidLoad方法中的UINavigationController的UINavigationBar添加一个Done"按钮UIViewController推送到UINavigationController.我在第一个视图的 top 上按的任何UIViewController都会自动在其中有一个后退"按钮,以导航到被掩盖的UIViewController.p>如果您在将
UIViewController放入UINavigationController的堆栈之前设置了title属性.UINavigationBar的标题将是您的视图的标题.同样,任何返回"按钮都会自动命名您要返回的视图,而不是一般地说返回".
I currently have a view set up as the following:
@interface BlogViewController : UIViewController <UITableViewDelegate, UITableViewDataSource> {
UITableView *mainTableView;
}
@property (nonatomic, retain) UITableView *mainTableView;
As you can see, it has a UITableView inside of it that I load all of my data to. However, when I call the following function:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
SingleBlogViewController *viewController = [[SingleBlogViewController alloc] init];
[self.navigationController pushViewController:viewController animated:YES];
//[self presentModalViewController:viewController animated:YES];
[viewController release];
}
nothing happens. For some reason my UITableView inside of my UIViewController isn't pushing the view. Is this because it isn't a UITableViewController? I tried changing it to that, and it still didn't work.
Am I missing something here?
I found the first parts of this blog post useful for showing how to create and use a UINavigationController programmatically without Interface Builder.
Some of the things I wish the docs and tutorials would have stressed to me:
When you create the
UINavigationControlleryou get a UIView and UINavigationBar for free (i.e. you don't need to separately add them and figure out how to hook them together).You add the
myUINavigationController.viewproperty as the "main" view and then push/popUIViewControllers onto the UINavigationController and they will automatically show up as visible in themyUINavigationController.viewUIView.When you push a
UIViewControlleronto aUINavigationController, theUIViewController.navigationControlleris filled in. If you haven't pushed the view onto the navigation controller, I'm guessing that property is empty.The time/place to programmatically add buttons to the
UINavigationBaris not when and where you construct theUINavigationController, but rather by the individualUIViewControllers when they are loaded as you push onto theUINavigationController.I only had to add a "Done" button to the
UINavigationController'sUINavigationBarin theviewDidLoadmethod of the firstUIViewControllerpushed onto theUINavigationController. AnyUIViewControllerI pushed on top of that first view automatically had a "back" button in the to navigate to the covered upUIViewController.If you set the
titleproperty of yourUIViewControllerbefore you put it on theUINavigationController's stack. TheUINavigationBars title will be the title of your view. As well any "back" buttons will automatically name the view you are returning to instead of generically saying "back".
这篇关于以编程方式在 UIViewController 中添加 UINavigationController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:以编程方式在 UIViewController 中添加 UINavigationController
基础教程推荐
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
