热门标签 | HotTags
当前位置:  开发笔记 > IOS > 正文

如何通过函数/方法调用SwiftUI模态表?

如何解决《如何通过函数/方法调用SwiftUI模态表?》经验,为你挑选了1个好方法。



1> RPatel99..:

的方式sheetactionSheetalert工作是你将它们连接到子视图,并决定是否要与条件结合显示它们。因此,您可以sheet在该视图的主体中将其附加到子视图,并为其提供条件绑定,以便您在要使用其调用模式的函数中进行更改。

例如,如果要显示带有按钮的工作表:

struct Battlefield : View {

    @State var isModalInputPresented: Bool = false
    @State var inputTitle: String = ""
    @State var inputMessage: String = ""
    @State var inputValue: Int = 0

    private func summonModalInput(title: String, message: String, input: Int) {
        self.isModalInputPresented.toggle()
        self.inputTitle = title
        self.inputMessage = message
        self.inputValue = input
        self.isModalInputPresented = true
    }

    var body: some View {
        Button(action: {
            summonModalInput(title: "foo", message: "bar", input: 0)
        }) {
            Text("Tap for an alert!")
        }
        .sheet(isPresented: $isModalInputPresented, 
            content: { 
                InputView(inputTitle: self.$inputTitle, inputMessage: self.$inputMessage, inputValue: self.$inputValue, isPresented: self.$isModalInputPresented)})
        }
    }
}


推荐阅读
author-avatar
乐乐>Witt
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有