我有这样的看法:

struct LoginButton : View {
    
    @Binding var showToastWrongLogin: Bool
    
    var body: some View{
        Button(action: {
            Task {
                等待Login.check Input()
            }
            
        }) {
            
        Text("Login")
            .padding(.vertical)
            .frame(maxWidth: .infinity)
            .foregroundColor(Color("ColorText"))
            .overlay(
                RoundedRectangle(cornerRadius: 5)
                    .stroke(Color.white, lineWidth: 0))
                
        }
        .background(Color("BtnDefaultBG"))
        .frame(minWidth: 0, maxWidth: .infinity)
        .cornerRadius(5)
        .padding(.top, 16)
    }
}

我正在try 调用位于Login内部的check Input()函数,该函数也是从其中调用此视图的

等待Login.check Input()

提供:

Instance member 'checkInput' cannot be used on type 'Login'; did you mean to use a value of this type instead?

请帮帮忙

推荐答案

如果我理解正确,Login是父视图,那么您可以在这里将函数作为参数注入,如下所示

struct LoginButton : View {

    @Binding var showToastWrongLogin: Bool
    let checkInput: () async -> Void         // << here !!

    var body: some View{
        Button(action: {
            Task {
                await checkInput()    // << here !!
            }

        }) {
...

Ios相关问答推荐

实例方法wait在异步上下文中不可用;请改用TaskGroup;这是Swift 6中的错误''

我想在expo 中使用useSafeAreaInsets来获取paddingbottom,但我得到了一个错误

设置堆栈视图的所有属性

在Android和iOS上从后台恢复应用程序后,inappwebview上出现白屏?

在SwiftUI中插入绘制重复形状

如何删除点击时按钮的不透明动画?

AVAudioRecord 没有音频

尽管存在浮点错误,如何显示正确的计算结果.计算器应用程序

Flutter Aging Person 自定义小部件

如何在 SwiftUI 中同时使用 LongPressGesture 和 ScrollView 中的滚动?

为 ColorPicker 创建一个名为 Color 的计算变量的绑定

将值传递给导航链接视图中的文本框

在 Swift 中合并子数组

iOS swift从另一个数组中删除一个数组的元素

interfaceOrientation在 iOS 8 中已弃用,如何更改此方法 Objective C

@IBDesignable 崩溃代理

什么是伞头?

在 UITableViewController 中使用 UISearchDisplayController 时断言失败

从 Swift 转换为 Objective-c 的工具

iOS应用程序每隔一次启动就会崩溃,找不到错误