OGeek|极客世界-中国程序员成长平台

标题: ios - Swift 3 - 多 View Controller 错误 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 17:53
标题: ios - Swift 3 - 多 View Controller 错误

目前,我正在为我的移动应用设计类(class)制作一个抽认卡应用。这是我的 SearchController.swift 文件代码

import UIKit
class SearchController: UIViewController {
    @IBOutlet weak var webView: UIWebView!
    var flashcard: Flashcard?
    let baseSearchURL = "https://google.com/search?q=apple developer"

    override func viewDidLoad() {
        super.viewDidLoad()
        if let card = flashcard,
            let escapedURLString = searchURLString(baseSearchURL, term: card.term),
            let url = URL(string: escapedURLString) {
                webView.loadRequest(URLRequest(url: url))
        }
    }

    fileprivate func searchURLString(_ base: String, term: String) -> String? {
        return "\(baseSearchURL) \(term)"
            .addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
    }
}

行:

let escapedURLString = searchURLString(baseSearchURL, term: card.term)

给出一个错误提示

"Missing argument label 'base:' in call"

行:

return "\(baseSearchURL) \(term)"

给出一个错误提示

"Static member 'init(stringInterpolationSegment' cannot be used on instance type of 'String'"

知道如何解决这个问题吗?



Best Answer-推荐答案


你要回来了

 return "\(baseSearchURL) \(term)"

这里你应该返回 base 而不是 baseSearchURL 之类的,

 return "\(base) \(term)"

缺少参数错误应该像这样解决,

  searchURLString(base: baseSearchURL, term: card.term)

关于ios - Swift 3 - 多 View Controller 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40145784/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (https://ogeek.cn/) Powered by Discuz! X3.4