swiftui

how to implement move on a grouped list in swiftui

拟墨画扇 提交于 2021-02-11 14:12:32
问题 how do i implement the onMove function in a grouped list? unfortunately i cannot see where i get the "to company" information from... here is the code: import SwiftUI struct Person: Identifiable, Hashable { var id = UUID() var name: String } struct Company : Identifiable, Hashable { var id = UUID() var name: String var employees : [Person] } class CompanyList: ObservableObject { @Published var companies = [ Company(name: "Apple", employees: [Person(name:"Bob"), Person(name:"Brenda")]),

In my NavigationView '.edgesIgnoringSafeArea' does not move content past the safe area

久未见 提交于 2021-02-11 14:00:16
问题 I would like it so that .edgesIgnoringSafeArea(.all) fits the content right onto the top of the canvas I would like it to show like this: https://i.stack.imgur.com/RzrO6.png Instead, it shows like this: https://i.stack.imgur.com/sbbaU.png Content view: TabView { NavigationView { MainContentView() } ... } Main content view: var body: some View { VStack(alignment: .leading, spacing: 20) { ... } .padding([.horizontal, .top]) .navigationBarTitle("Title") } Detailed view: struct PostDetail: View {

SwiftUI Text Behavior

…衆ロ難τιáo~ 提交于 2021-02-11 13:56:16
问题 I am seeing some odd Text field behavior on my device that I did not see in the simulator. I have a standard grouping of text fields within a VStack that call from an @ObservedObject variable, like follows: @ObservedObject var timer: ActivityTimer var body: some View { VStack { VStack { Text(timer.currentCountdownString).font(Font.system(size: 90)) Text(timer.currentActivityName).font(.largeTitle).bold().underline().padding(.bottom, 5) Text(timer.currentIncline).font(.title) } .padding()

How to add a clickable button in a List without triggering NavigationLink event?

心不动则不痛 提交于 2021-02-11 13:46:41
问题 I have a button in a list item and when I click on it, the NavigationLink's event is also being triggered. I only want to trigger the button event. How to do it? following is my code: ForEach(self.cares,id:\.id){ care in HStack{ if(care.markMode == "打卡"){ Button("今日未打卡"){ } else{ Button("新增记录"){ self.care = care self.showSheetNewMark.toggle() } } NavigationLink(destination:CareDetailView(care: care)){ Text("\(care.nickname!)的\(care.subject!)") } } } 回答1: Add PlainButtonStyle for button, as in

How to add a clickable button in a List without triggering NavigationLink event?

泄露秘密 提交于 2021-02-11 13:44:29
问题 I have a button in a list item and when I click on it, the NavigationLink's event is also being triggered. I only want to trigger the button event. How to do it? following is my code: ForEach(self.cares,id:\.id){ care in HStack{ if(care.markMode == "打卡"){ Button("今日未打卡"){ } else{ Button("新增记录"){ self.care = care self.showSheetNewMark.toggle() } } NavigationLink(destination:CareDetailView(care: care)){ Text("\(care.nickname!)的\(care.subject!)") } } } 回答1: Add PlainButtonStyle for button, as in

SwiftUI Preview issue with @State and CoreData

牧云@^-^@ 提交于 2021-02-11 13:42:11
问题 I'm having trouble getting a preview to work with what seems like a pretty simple struct. Customer is a CoreData entity: struct CustomerDetailView: View { @Environment(\.managedObjectContext) var moc @State var showNewCustomer = false var customer: Customer var body: some View { I've tried almost everything that doesn't work, including this: struct CustomerDetail_Previews: PreviewProvider { static var previews: some View { let context = (UIApplication.shared.delegate as! AppDelegate)

SwiftUI: How could I show the new View base on the current Scene

﹥>﹥吖頭↗ 提交于 2021-02-11 13:42:07
问题 First, my step is just follows: Open my application(called appA), and it show the MainHome View Back to the launcher, and call another application(called appB), and click the export file to the appA And now it would call the function: func scene(_ scene: UIScene, openURLContexts URLContexts: Set<UIOpenURLContext>) { My problem is how could I show the ImportHome base on the MainHome and click the back button in the ImportHome could back to MainHome? My source code is just as follow: class

Why does SwiftUI throw errors when I try to use control flow?

醉酒当歌 提交于 2021-02-11 13:27:15
问题 Why does SwiftUI like to throw errors like Closure containing control flow statement cannot be used with function builder 'ViewBuilder' When I simply try something like VStack { for i in 0...10 { Text("Hello, world!") } } It will not compile. Why does swift care? How does the SwiftUI framework even detect if there are control flow statements, and throw errors? 回答1: How does the SwiftUI framework even detect if there are control flow statements, and throw errors? It doesn't. The Swift language

Why does SwiftUI throw errors when I try to use control flow?

烂漫一生 提交于 2021-02-11 13:26:28
问题 Why does SwiftUI like to throw errors like Closure containing control flow statement cannot be used with function builder 'ViewBuilder' When I simply try something like VStack { for i in 0...10 { Text("Hello, world!") } } It will not compile. Why does swift care? How does the SwiftUI framework even detect if there are control flow statements, and throw errors? 回答1: How does the SwiftUI framework even detect if there are control flow statements, and throw errors? It doesn't. The Swift language

SwiftUI insertion transion is not working when view added

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-11 13:13:59
问题 I'm trying SwiftUI tutorial in apple developer page. now I'm following transition tutorial but my transition is not working when the view added. here my code. VStack(alignment: .leading) { HStack() { // title Text(titleText) .font(.headline) .padding() Spacer() // button Button(action: { withAnimation { self.showDetail.toggle() } }) { Image(systemName: "chevron.right.circle") .imageScale(.large) .rotationEffect(.degrees(showDetail ? 90 : 0)) .padding() } } // detail if showDetail { Text