2017-10-08 21 views
0

fav.tableview.insertRows関数を除いてすべてが呼び出されますが、エラーは発生しませんが、エラーは発生しませんが、呼び出しは行われません。コンソールで何かを印刷することです。swift 3関数が呼び出されていない


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() 
     } 

クラスのお気に入り:お使いの場合の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 



} 

}

+0

私はあなたがこのようnumberOfRowsInSectionを変更する必要があると思う(の:!newItemを)されなし。コンソールで 'po wrds.favorite_words.index(of:newItem!)'を試して、結果を確認してください。 – MEnnabah

+0

私はブレークポイントをしようとしましたが、if文の中に入り、内部のすべての関数を処理します。insertRowsは動作しません。新しい行を挿入しません。 –

+0

'お気に入り'は何ですか? – MEnnabah

答えて

1

ポイントあなたの関数の左側にマウスカーソルが呼び出される、丸い点があるはずですボタンがこの機能に接続されている場合は、ドットをクリックすると、ポップアップリストに表示されているボタンが表示されます。

あなたの問題は、コードとストーリーボードの間、またはストーリーボード上のみである必要があります。

0

wrds.copiedarraynumberOfRowsInSectionに使用しています。

wrds1.favorite_wordscellForRowである。あなたがもし条件内でブレークポイントを設定して、wrds.favorite_words.indexつまり、あそこに停止していない場合

override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return wrds1.favorite_words.count 
} 
関連する問題