настройка заголовка панели навигации swiftUI при использовании с контроллером просмотра - PullRequest
0 голосов
/ 19 июня 2020

страница ячеек

ChatView

вот код страницы моих ячеек

    var body : some View{
        NavigationView {
            List(getPairsUser()){i in

                NavigationLink(destination: ChatView(friend:i)){
                    cellView(user : i)
                }
                .navigationBarTitle(Text("Friends List"),displayMode: .inline)
            }
                .navigationBarHidden(true)


        }.frame(minWidth: UIScreen.main.bounds.width, idealWidth: UIScreen.main.bounds.width, maxWidth: UIScreen.main.bounds.width,  maxHeight: .infinity)
            .clipShape(Rounded())

    }

в навигационной ссылке ChatView ()

и код ChatView здесь

struct ChatView: UIViewControllerRepresentable {

    @EnvironmentObject var obser:Observer


    var db = Firestore.firestore()
    var friend:User!
    var messageRef:CollectionReference!
    var pairRef:CollectionReference!

    init(friend:User){
        self.friend = friend

    }

    func updateUIViewController(_ uiViewController: ChatViewController, context: Context) {
        if(uiViewController.left){
            if(!self.obser.messageListenerFlag[friend.pairUid]!){
                self.obser.messageListenerFlag[friend.pairUid] = true
                if( uiViewController.lastMessageDate != nil){
                    self.obser.pairLastMessages[friend.pairUid] = uiViewController.lastMessage
                    self.obser.pairLastMessagesDate[friend.pairUid] = uiViewController.lastMessageDate
                }
            }

        }

    }
    func makeUIViewController(context: Context) -> ChatViewController {
        let chatViewController = ChatViewController()
        chatViewController.navigationItem.title = self.friend.name

        self.navigationBarTitle(Text(self.friend.name))


        chatViewController.title = self.friend.name
        chatViewController.senderId = self.obser.__THIS__.Uid
        chatViewController.senderDisplayName = self.obser.__THIS__.Name
        chatViewController.friend = self.friend
        chatViewController.messageRef = self.db.collection("pairs").document(self.friend.pairUid).collection("messages")
        chatViewController.pairRef = self.db.collection("pairs").document(self.friend.pairUid).collection("typingIndicator")
        chatViewController.__THIS__ = self.obser.__THIS__

        let _url = URL(string: self.friend.image)!
        if let data = try? Data(contentsOf: _url) {
            chatViewController.friendImage = UIImage(data: data)
        }

        self.obser.messageListenerFlag[friend.pairUid] = false




        self.obser.unreadMessageCount[friend.pairUid]? = 0


        return chatViewController
    }

    typealias UIViewControllerType = ChatViewController

}

, и что я хочу сделать, так это войти в ChatView

Я хочу добавить текст (имя друга) в оранжевый блок (на картинке)

Я уже пытаюсь добавить .navigationTitle на страницу ячеек, но это не работает

также я пытаюсь изменить заголовок viewcontroller, но это не так тоже работать

как мне сделать?

1 Ответ

0 голосов
/ 20 июня 2020

Прежде чем я отвечу на ваш вопрос, извините за то, что обошелся без теста. Это просто основано на моем предположении.

Установить chatViewController.navigationItem.title = self.friend.name вместо вызова navigationBarTitle представления SwiftUI.

Я думаю, что выдвинутое представление - это не обычный SwiftUI, а представление представления UIKit, поэтому вы должны обрабатывать его в манере UIKit.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...