【问题标题】:"Return from initializer without initializing all stored properties" error in SwiftUISwiftUI 中的“从初始化程序返回而不初始化所有存储的属性”错误
【发布时间】:2020-07-09 07:00:06
【问题描述】:

我正在尝试使用 init() 使导航栏透明,但我收到错误“从初始化程序返回而不初始化所有存储的属性”,我不知道如何解决它。这是我的代码:

import SwiftUI

struct DoctorHomePage: View {

    @Binding var shouldPopToRootView : Bool
    @State var hiddingNavBar = true
    @State private var curent: Int? = nil
    @State private var profileSegue: Int? = nil
    @State private var isActive: Bool = false
    let defaults = UserDefaults.standard
    let networkRequest = Network()
    @State var cancelable: AnyCancellable? = nil
    @State var localPatients : [Patients] = []
    @Environment(\.colorScheme) var colorScheme: ColorScheme
    @State private var isShowing = false

    init() {
        UINavigationBar.appearance().backgroundColor = .clear
        UINavigationBar.appearance().setBackgroundImage(UIImage(), for: .default)
    } // I get the error here

    var body: some View {
        NavigationView {
            VStack {
               Text("Hello, World!")
            }
        }
    }
}

【问题讨论】:

  • 如果您单击错误消息旁边的红点,那么 Xcode 11.4 会告诉您“'self.shouldPopToRootView' 未初始化”。

标签: ios swift swiftui init


【解决方案1】:

你还没有初始化shouldPopToRootView

【讨论】:

    猜你喜欢
    • 2021-06-28
    • 1970-01-01
    • 2015-06-22
    • 2017-12-31
    • 2017-01-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    相关资源
    最近更新 更多