English 中文(简体)
我如何在快速倡议中以方案方式设定“国家”
原标题:How do I set an @State variable programmatically in SwiftUI

我有一项控制,即:@State,变量,以追踪在海关表格中选定的表格。 我可在编码中设定<代码>@State>变量,规定如下:

@State var selectedTab: Int = 1

我如何从方案上确定初步价值,以便我能够在形成观点时改变选定的表格?

我已尝试如下:

:

@State var selectedTab: Int = (parameter == true ? 1 : 2)

:

init(default: Int) {
    self.$selectedTab = default
}
问题回答

我的看法之一是,我如何确定初步的国家价值观:

struct TodoListEdit: View {
    var todoList: TodoList
    @State var title = ""
    @State var color = "None"

    init(todoList: TodoList) {
        self.todoList = todoList
        self._title = State(initialValue: todoList.title ?? "")
        self._color = State(initialValue: todoList.color ?? "None")
    }

Joe Groff: “@State sediments 不应从你通过初始器通过的数据中初步得出数据。 正确的做法是将你最初的国家价值观定在一条线上:”

选择的国家 Tab: Int = 1

你们应该利用一项约束手段,让你们能够接触到你认为当地的国家。

www.un.org/Depts/DGACM/index_french.htm Tab: Int

然后,你可以主动地开始,你仍然可以把它传给儿童。

资料来源:https://forums.swift.org/t/state-messing- with- initializer-flow/25276/3





相关问题
SwiftUI: How do I position a button x points above a sheet?

I am trying to recreate a Maps-style UI with a persistent bottom sheet and controls fixed above. Apple Maps UI with controls above ☝️ Example here, the "Look Around" binoculars button and ...

BraintreeDropIn deprecated functions error

I m getting this error on the latest release of BraintreeDropIn, I really don t get it since based on the patch notes, this should ve been addressed already, I have already tried cleaning derived data,...

how to limit zoom level in map swift ui?

how to limit zoom level in map swift ui i have map and need to make zoom level limited Map(coordinateRegion: $region,annotationItems: viewModel.nearbyGyms) { item in ...

UIImageView - How to get the file name of the image assigned?

Is it possible to read the name of an UIImageView s UIImage that s presently stored in the UIImageView? I was hoping you could do something kind of like this, but haven t figured it out. NSString *...

热门标签