问题描述
我正在尝试将SwiftUI集成到我的项目中,并且我目前正在使用一个故事板,该故事板是通过我的应用程序委托使用以下代码启动的:
CreatableSelect
因此,基本上我的App委托位于Objective-c中,而Windows根控制器是UINavigation控制器。
我的Basicinformation类如下:
_rootNavigiationController = [[UINavigationController alloc] init];
_rootNavigiationController.navigationBarHidden = YES;
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:StoryboardLoginRegister bundle:nil];
Basicinformation *basicInfo = (Basicinformation *)[storyboard instantiateViewControllerWithIdentifier:@"basic-info"];
[self.rootNavigiationController setViewControllers:@[basicInfo]];
Swift UI的基本信息如下:
class BasicInfo: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = true;
// Do any additional setup after loading the view.
}
@IBSegueAction func addSwiftUi(_ coder: NSCoder) -> UIViewController? {
let BasicInfoUI = BasicInfo_UI();
let hostingController = UIHostingController(coder: coder,rootView: BasicInfoUI);
hostingController?.navigationController?.isNavigationBarHidden = true;
return hostingController;
}
/*
// MARK: - Navigation
// In a storyboard-based application,you will often want to do a little preparation before navigation
override func prepare(for segue: UIStoryboardSegue,sender: Any?) {
// Get the new view controller using segue.destination.
// Pass the selected object to the new view controller.
}
*/
}
我唯一的问题是我似乎无法弄清楚为什么我的应用程序UI顶部有一个导航栏
希望有人可以向我解释为什么我的控制器事件顶部确实有一个导航栏,尽管我已经在我的应用中的多个位置上明确将Navigationbarhidden设置为true
解决方法
尝试通过SwiftUI明确隐藏导航栏,例如
Form {
// ... other code
}
.navigationBarTitle("")
.navigationBarHidden(true)