我正在尝试实现CNContactViewDelegate
能够显示CNContact
. 显然,我是第一个实施它SwiftUI
并遇到问题的人。无论如何,我可以看到使用的细节,CNContact
但UIViewControllerRepresentable
我有一个问题,在图像和之间NavigationBar
存在差距-因为我认为-并且本机应用程序中不存在这种差距,显然在这个中实现框架的链接。Contact
StatusBar
NavigationBar
NavigationLink
Contacts
UIKit
这是代码;
struct ContactsListView: View {
@ObservedObject var contactsModel: ContactsViewModel
var body: some View {
NavigationView{
List {
//After some ForEach's and Section's
//This view is working.
NavigationLink(destination: ContactDetailView(contact: self.$contactsModel.contacts[sectionIdx].contacts[contactIdx])) {
Text(self.contactsModel.contacts[sectionIdx].contacts[contactIdx].givenName)
}
}
.navigationBarTitle("Contacts")
}
}
}
struct ContactView: UIViewControllerRepresentable {
@Binding var contact: CNContact
func makeCoordinator() -> ContactView.Coordinator {
Coordinator(self)
}
func makeUIViewController(context: UIViewControllerRepresentableContext<ContactView>) -> CNContactViewController {
let controller = CNContactViewController(for: contact)
self.navigationBarHidden(true)
return controller
}
func updateUIViewController(_ uiViewController: CNContactViewController, context: UIViewControllerRepresentableContext<ContactView>) {
print(context)
}
class Coordinator: NSObject, CNContactViewControllerDelegate {
var parent: ContactView
init(_ contactDetail: ContactView) {
self.parent = contactDetail
self.parent.navigationBarHidden(true)
}
}
}
在 中ContactView
,这两个self.navigationBarHidden(true)
都不起作用。此处的问题示例是本机应用程序的屏幕截图;
这是我的代码的结果;