gpt4 book ai didi

swift 3 一个函数没有被调用

转载 作者:行者123 更新时间:2023-11-28 15:17:11 26 4
gpt4 key购买 nike

当我点击 addFavoriteButton 时,除了 fav.tableview.insertRows 函数之外的所有内容都被调用,它不会崩溃或给我一个错误,但它不是被调用,因为如果它被调用,它应该做的第一件事就是在控制台中打印一些东西。


import UIKit

class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource, UISearchBarDelegate {



// var favorites: favorites!
var store: Store!

var copiedarray = [String]()

var wrds: manager_class = manager_class()
var fav: favorites = favorites()
//var historyObject: historyTableView = historyTableView()




@IBOutlet var addFavoriteButton : UIButton!
@IBOutlet var favorite: UIButton!


@IBOutlet var TranslationLanguages: UIPickerView!
@IBOutlet var translationLangTest: UILabel!

@IBOutlet var SearchBar: UISearchBar!

let arabic = ["مادي", "بسيط", "معقد", "سيارة"]
let english = ["Concrete", "Simple", "Complex", "Car"]
let french = ["Concret", "Simple", "Comlexe", "Car"]

let languages = ["Pick a language","English to Arabic" , "English to French" , "Arabic to English" , "Arabic to French" , "French to English" , "French to Arabic"]




@IBAction func addFavoriteButton(_ sender: Any) {

print(SearchBar.text!)
if (SearchBar.text?.isEmpty)! {
return
}
for item in wrds.favorite_words {
if item == SearchBar.text {
print("item is already in favorite!")
return
}

}

wrds.favorite_words.append(SearchBar.text!)
//print(wrds.favorite_words)
let newItem = wrds.favorite_words.last


if let index = wrds.favorite_words.index(of: newItem!) {

let indexPath = IndexPath(row: index, section: 0)
fav.tableView.beginUpdates()
fav.tableView.insertRows(at: [indexPath], with: .automatic)
fav.tableView.endUpdates()
}

类(class)收藏夹:UITableViewController {

var wrds1: manager_class = manager_class()

var store: Store!

//var tableCell = TableViewCell()
var copiedarray1 = [String]()
//let cell1: TableViewCell = TableViewCell()



override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
print("i am inside table view!")
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell", for: indexPath) as! TableViewCell
print(wrds1.favorite_words.isEmpty)
print("Heloo")


let word = wrds1.favorite_words[indexPath.row]
cell.favoriteWordInTable?.text = word


return cell
}



override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

return copiedarray1.count
}
override func tableView(_ tableView: UITableView, titleForFooterInSection section: Int) -> String? {
let title = "favorites"
return title
}
override func viewDidLoad() {


let wrds: ViewController = ViewController()
//let wrds1: manager_class = manager_class()

copiedarray1 = wrds.copiedarray



}

最佳答案

将鼠标光标指向要调用的函数的左侧,应该有一个圆点,如果你的按钮连接到这个函数,当你点击圆点时,你应该看到弹出列表中显示的按钮。

你的问题应该是代码和storyboard之间的联系,或者只是在storyboard上。

关于swift 3 一个函数没有被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46629773/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com