【问题标题】:Navigation Link suddenly not working after 1 day导航链接在 1 天后突然不起作用
【发布时间】:2020-07-02 09:06:30
【问题描述】:

昨天,对我来说一切正常,但是当我今天运行应用程序时(使用相同的代码!)我的导航链接将无法正常工作。我真的不知道问题出在哪里。 我对 swift 很陌生,所以它可能是非常明显的。

这是在按下导航链接时在控制台中:

2020-03-20 22:53:12.447955+0100 To Do App[2650:175993] [ProcessSuspension] 0x10de7c450 - ProcessAssertion::processAssertionWasInvalidated()

列表项的代码:

import SwiftUI

struct ToDoItemView: View {
    static let taskDateFormat: DateFormatter = {
        let formatter = DateFormatter()
        formatter.dateStyle = .medium
        formatter.timeStyle = .short
        formatter.timeZone = .current
        return formatter
    }()



    @State var title:String = ""
    @State var info:String = ""
    var createdAt:Date = Date()
    @State var until:Date = Date()
    var body: some View {
        HStack{
            if info == "" || "\(until)" == ""{
                Text(title)
                        .font(.headline)
                Spacer()
                Text("\(until, formatter: Self.taskDateFormat)")
                    .font(.caption)
            }else{
                Text(title)
                    .font(.headline)
            Spacer()
            Text("\(createdAt, formatter: Self.taskDateFormat)")
                .font(.caption)




            NavigationLink(destination: ModalView(title: self.$title, info: $info, until: $until)){
                Image(systemName: "arrow.down")
                    .foregroundColor(.clear)
                }
            }

        }
        .padding(.horizontal)


    }
}

【问题讨论】:

    标签: swift xcode swiftui xcode11


    【解决方案1】:

    缺少导航视图。添加相同的内容。

    var body: some View {
        NavigationView {
            HStack{
                if info == "" || "\(until)" == ""{
                    Text(title)
                            .font(.headline)
                    Spacer()
                    Text("\(until, formatter: Self.taskDateFormat)")
                        .font(.caption)
                }else{
                    Text(title)
                        .font(.headline)
                Spacer()
                Text("\(createdAt, formatter: Self.taskDateFormat)")
                    .font(.caption)
    
    
    
    
                NavigationLink(destination: ModalView(title: self.$title, info: $info, until: $until)){
                    Image(systemName: "arrow.down")
                        .foregroundColor(.clear)
                    }
                }
    
            }
            .padding(.horizontal)
       }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-22
      • 2018-03-25
      • 1970-01-01
      • 2017-08-31
      • 2021-11-29
      • 1970-01-01
      相关资源
      最近更新 更多