swiftui“没有参数”使用网站链接时错误

发布于 2025-02-12 15:29:41 字数 1554 浏览 0 评论 0原文

我正在开发一个简单的联系人应用程序,当添加下面显示的行时,我会收到错误:传递给呼叫的参数,该呼叫没有参数。

let websitetext: String
init(){
    self.websitetext = contact.website
}

以下是删除无关数据的整个文件。

import Foundation
import SwiftUI

struct ContactsDetailView: View{
    let contact: Contact
    let websitetext: String //lines referenced
    init(){
        self.websitetext = contact.website
    }

    var body: some View {
        
        HStack{
            VStack {
                Image(contact.imageName)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 100, height: 100)
                    .clipped()
                .cornerRadius(50)
            
                Text(contact.name)
                    .font(.system(size: 21, weight:.medium, design: .default))
                Form{
                    HStack {
                        Text ("Phone")
                        Spacer()
                        Text(contact.phone)
                            .foregroundColor(.gray)
                            .font(.callout)
                    }
                    Section{
                        Link("Website", destination: URL(string:  websitetext)!) //Uses the website text variable
                    }
                }
                
            }
        }
    }
}

struct ResourcesDetailView_Previews: PreviewProvider {
    static var previews: some View {
        ContactsDetailView(contact: contacts[0]) //ERROR LINE
    }
}

解决此问题的任何帮助将不胜感激!

I'm developing a simple contacts application, when adding the lines shown below, I receive the error: Argument passed to call that takes no arguments.

let websitetext: String
init(){
    self.websitetext = contact.website
}

Below is the entire file with irrelevant data removed.

import Foundation
import SwiftUI

struct ContactsDetailView: View{
    let contact: Contact
    let websitetext: String //lines referenced
    init(){
        self.websitetext = contact.website
    }

    var body: some View {
        
        HStack{
            VStack {
                Image(contact.imageName)
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width: 100, height: 100)
                    .clipped()
                .cornerRadius(50)
            
                Text(contact.name)
                    .font(.system(size: 21, weight:.medium, design: .default))
                Form{
                    HStack {
                        Text ("Phone")
                        Spacer()
                        Text(contact.phone)
                            .foregroundColor(.gray)
                            .font(.callout)
                    }
                    Section{
                        Link("Website", destination: URL(string:  websitetext)!) //Uses the website text variable
                    }
                }
                
            }
        }
    }
}

struct ResourcesDetailView_Previews: PreviewProvider {
    static var previews: some View {
        ContactsDetailView(contact: contacts[0]) //ERROR LINE
    }
}

Any help to solve this issue would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文