提问人:dbenitobaldeon 提问时间:7/21/2020 最后编辑:dbenitobaldeon 更新时间:7/21/2020 访问量:76
在 UINavigationController 类中设置 RootViewController - 目标 C
Set RootViewController in UINavigationController class - Objective C
问:
我是使用 Objective C 的新手,我对情节提要有很好的了解,但现在我尝试通过代码更改 UINavigationController 的根视图控制器,碰巧它依赖于一个变量,我将设置根,但我不知道如何配置这个操作除了我的 UINavigationController 的自定义类。我希望你能帮助我。请记住,此视图是应用程序中的第三个屏幕。
@interface PCCatalogNavigationController () <UINavigationControllerDelegate>
@end
@implementation PCCatalogNavigationController
- (void)viewDidLoad{
if (status == 1){
//TableViewViewController
} else {
//Optional StarViewController
}
}
@end
答:
0赞
Hitesh patel
7/21/2020
#1
在您的应用程序委托中,只需添加导航控制器的属性即可
@property (nonatomic , strong) UINavigationController *navigationController;
和内部
-(BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
TableViewViewController *TableViewView = [[UIStoryboard
storyboardWithName:@"Main" bundle:nil]
instantiateViewControllerWithIdentifier:@"TableViewViewController"];
StarViewController *StarView = [[UIStoryboard
storyboardWithName:@"Main" bundle:nil]
instantiateViewControllerWithIdentifier:@"StarViewController"];
if (status == 1){
self.navigationController =
[[UINavigationController alloc]
initWithRootViewController:TableViewView];
} else {
//Optional
StarViewController self.navigationController =
[[UINavigationController alloc]
initWithRootViewController:StarView];
}
}
代替 UINavigationController,您可以使用 customNavigationcontroller
评论
2赞
zrzka
7/21/2020
请格式化您的答案,使其至少可读,谢谢。
1赞
dbenitobaldeon
7/21/2020
请更好地解释您的答案。我更新了我的问题。@zrzka
0赞
Ol Sen
7/21/2020
此代码将不起作用。将 instanciateViewControllerWithIdentifier:@“TableViewViewController” 强制转换为不同的 ViewController 类两次,并为相同的 UINavigationController 分配相同的 UINavigationController。因此,代码总共被编写了两次,除了在分配中丢失的强制转换之外,没有任何效果。并且该方法不返回任何内容
0赞
Hitesh patel
7/21/2020
这是我这边的一个错别字错误@OlSen谢谢伙计
评论