Posts

Post not yet marked as solved
7 Replies
9.3k Views
This List in the first page of a tab view. When a cell is tapped, I want to show a new ChatRoomDetail view and hide tab bar. But I couldn't find a way in documentation. How should I do it? Thanks!struct ChatList: View { @State var showChatRoomDetail: Bool = false var items: [ChatRoom] var body: some View { NavigationView { List { ForEach(self.items) { item in NavigationLink(destination: ChatRoomDetail(currentMessage: "", chatRoom: item)){ Text(item.titleString) } } }
Posted
by andykuang.
Last updated
.
Post not yet marked as solved
0 Replies
343 Views
I updated Xcode to 11.4 today and immediately found unexpectd behavior. Below is a simple view to display all messages in a chat room. When a new message is downloaded from server, the list refreshed automatically to display it. But with Xcode 11.4 and ios 13.4, with a 50:50 chance, a new chat room view will (unexpectly) pop up and all rows behave abnormally. Is there anybody experiencing the same? My code below:import SwiftUIstruct ChatRoomDetailView: View { @EnvironmentObject var userData: UserData @State var messageText: String = "" @State var isShowingGroupOperation = false var displayChatRoom: ChatRoom var thisRoomtitle: String { if displayChatRoom.isPrivate { if (displayChatRoom.creatorId == userData.currentUser.name) {return userData.friendNickNames[displayChatRoom.otherUser] ?? displayChatRoom.chatRoomTitle} else {return userData.friendNickNames[displayChatRoom.creatorId] ?? displayChatRoom.chatRoomTitle} } else {return displayChatRoom.chatRoomTitle} } func findIndex(chatRoomId: Int) -> Int { for (index, value) in userData.chatRooms.enumerated() { if (value.id == chatRoomId) {return index} } return 0 } var body: some View { KeyboardHost { VStack { List { ForEach(self.displayChatRoom.messages) {message in HStack{ if (message.senderId == self.userData.currentUser.name) { SelfMessageLine(message: message) } else {OtherMessageLine(message: message)} } } .onDelete {indexSet in self.userData.deleteMessage(displayChatRoomId: self.displayChatRoom.id, id: self.displayChatRoom.messages[indexSet.sorted()[0]].id) } }......
Posted
by andykuang.
Last updated
.
Post not yet marked as solved
2 Replies
1.6k Views
I put a TableView inside a TabView, which is quite simple.struct ContentView: View { var body: some View { TabView() { FirstTab().tabItem { Text("Tab Label 1") }.tag(1) Text("Tab Content 2").tabItem { Text("Tab Label 2") }.tag(2) } }}struct FirstTab: View { var body: some View { List { ForEach (data) { point in Text("No. \(point.id) point distance is \(point.r).") } } }}But when FirstTab appears, Xcode gave me this warning:2019-11-15 11:47:25.696111+0800 testTab[1775:51174] [TableView] Warning once only: UITableView was told to layout its visible cells and other contents without being in the view hierarchy (the table view or one of its superviews has not been added to a window). This may cause bugs by forcing views inside the table view to load and perform layout without accurate information (e.g. table view bounds, trait collection, layout margins, safe area insets, etc), and will also cause unnecessary performance overhead due to extra layout passes. Make a symbolic breakpoint at UITableViewAlertForLayoutOutsideViewHierarchy to catch this in the debugger and see what caused this to occur, so you can avoid this action altogether if possible, or defer it until the table view has been added to a window. Table view: <_TtC7SwiftUIP33_BFB370BA5F1BADDC9D83021565761A4925UpdateCoalescingTableView: 0x7f9ba1038000; baseClass = UITableView; frame = (0 0; 414 756); clipsToBounds = YES; autoresize = W+H; gestureRecognizers = <NSArray: 0x60000149c990>; layer = <CALayer: 0x600001abab40>; contentOffset: {0, 0}; contentSize: {414, 0}; adjustedContentInset: {0, 0, 83, 0}; dataSource: (null)>What does this mean? Why table view "has not been added to a window"?
Posted
by andykuang.
Last updated
.
Post not yet marked as solved
5 Replies
1k Views
I am using SwiftUI and had no problem with Xcode 11.1. But it will crash in Xcode 11.2. Just downloaded 11.2.1, and the same problem.My code is here: first, there is a NavigationView. Inside that NavigationView, there is a TabView.struct ContentView: View { let titleStringArray = ["Chat", "Contacts", "Radio","Settings"] @EnvironmentObject var userData: UserData @State var currentStatus: Int = 0 var body: some View { NavigationView { if userData.idCheckPassed { TabView { ChatList() .tabItem { Image(systemName: "bubble.left.and.bubble.right.fill") Text("Chat") } .........Below, is the first tab, ChatList View. Inside this ChatList View, there is a NavigationLink. The target of this NavigationLink (ChatRoomDetail) has a textview. Every time when I try to go back from the ChatRoomDetail, my app crashed.struct ChatList: View { @EnvironmentObject var userData: UserData var body: some View { List { ForEach(userData.chatRooms) { item in NavigationLink(destination: ChatRoomDetail(chatRoom: item)){ Text(item.titleString) }}}}}Looks like 11.2.1 did not solve the problem.
Posted
by andykuang.
Last updated
.