2016-10-15 3 views
0

ViewController with a single tableViewの優れた書き込みアップにフォローアップして、カスタムセルを有する複数のUITableViewsをswift3、私は2別々の tableViewsと独立してそれぞれ1つに属するカスタムセルを有する者への質問を拡張したいと思います。xcode8が

現時点では、私は半加工のスケルトンを持っていますが、これを解決するためのよりエレガントで簡単ではない方法があると確信しています。

  • のviewDidLoad()
vInfoTV.dataSource = self 
vInfoTV.delegate = self 
vInfoTV.tag = Int.min 

vAppTV.dataSource = self 
vAppTV.delegate = self 
vAppTV.tag = Int.max 
  • numberOfRowsInSection機能
func tableView(_ tableView: UITableView, numberOfRowsInSection section:Int) -> Int { 
    if tableView.tag == Int.min { 
     return mydata.cats.count 
    } else { 
     return mydata.dogs.count 
    } 
} 

はそれが私がここで行うようにtableViewさんのタグを設定し、それらをスイッチオンすることが適切である後タグの値に基づいていますか? func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

if tableView.tag == Int.min { 
    // Cat Table View 
    if indexPath.row == 0 { 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "firstCustomCell") 
     //set the data here 
     return cell 
    } 
    else if indexPath.row == 1 { 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "secondCustomCell") 
     //set the data here 
     return cell 
    } 
    else { 
     let cell: UITableViewCell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: "thirdCustomCell") 
     //set the data here 
     return cell 
    } 


} else { 
    // Dog Table View 
    if indexPath.row == 0 { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "poodleCell", for: indexPath) as! NewApplicationViewCell 
     cell.typeL.text = Dogs[(indexPath as NSIndexPath).row].type 
     return cell 
    } 
    else { 
     let cell = tableView.dequeueReusableCell(withIdentifier: "mastifCell", for: indexPath) as! InitialDMVInspectionTableView 
      cell.typeL.text = Dogs[(indexPath as NSIndexPath).row].type 
     return cell 
    } 
} 
    • 細胞今は細胞(すなわちデータなし)を持っていないのtableViewを、隠すための最良の方法は何ですか?

    これは正しい方法ですか?コメントはすべて歓迎します!

    感謝!

答えて

1
  1. 私がここで行うようにtableViewのタグを設定し、タグ値に基づいてスイッチを入れることは適切ですか?

    はい、あなたは私がやる方法とまったく同じでした。テーブルのタグを別々に設定します。しかし、私はInt.minやInt.maxとは言いません。むしろ、私はtableviewsのタグとして何を設定したのかをすぐに知りたいと思っています。だから、私は99と100のような数字を選ぶでしょう。私が0と1を選んでいない理由は、デフォルトでオブジェクトのタグは0です。つまり、99を置くと、私のビューの中で別のテーブルビューをドラッグしても、前のテーブルビューとはまだ矛盾しません。

  2. セルがない(つまりデータがない)tableViewを非表示にする最良の方法は何ですか? numberOfRowsInSectionのようにデータがない場合、テーブルビューは表示されません。行番号を目的のデータ配列のデータ数に設定します。

関連する問題