2017-04-18 7 views
-1

iOS開発を初めて利用しています。現在、私は2つ以上のUITableViewを1つのView Controllerで使用するプロジェクトに取り組んでいますが、両方のデータソースはサーバーごとに1つずつ表示されます。最初のAPIがヒットしたときに結果が表示されますが、そのリストから項目を選択した後、リストに回答を表示できません。ここでシングルビューで複数のUITableViewを使用する方法iOSのコントローラ - Swift

は私のコードです:事前

+0

正しいです。このコードにはどのような問題がありますか? – KKRocks

+0

画面に表示されているtableViewのうち、どれですか? –

+0

の問題は、2番目のuitableviewに何も表示されないということです。 –

答えて

0

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    print("sdfsdfsf") 
    var count:Int? 
    if tableView == self.pat_search_listview { 
     count = serach_data.count 
    } 
    else if tableView == self.visit_listview { 
     count = all_vist_data.count 
    } 
    return count! 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = UITableViewCell() 
    if tableView == self.pat_search_listview { 
     cell.textLabel?.text = serach_data[indexPath.row].name + "  " + serach_data[indexPath.row].id 
    } 


    else if tableView == self.visit_listview { 
     print("second listview") 
     cell.textLabel?.text = all_vist_data[indexPath.row].date 
    } 

    return cell 
} 

おかげで、両方のtableViews用コンセントの接続を確認してください...両方とものviewDidLoadでのviewDidLoad

ではnilであってはならない。

self.pat_search_listview.dataSource = self; 
self.visit_listview = self; 

self.pat_search_listview.tag = 0 
self.visit_listview.tag = 1 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

if tableView.tag == 0 
... 
else 
... 
-1

デリゲートとデータソースを設定してください。アレイの追加/更新後にテーブルをリロードすることを忘れないでください。

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int 
{ 
    if tableView == self.pat_search_listview 
    { 
     return serach_data.count/*pat_search_listview's Array count*/ 
    } 
    else if tableView == self.visit_listview 
    { 
     return all_vist_data.count/*visit_listview Array count*/ 
    } 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = UITableViewCell() 

    if tableView == self.pat_search_listview 
    { 
     cell.textLabel?.text = serach_data[indexPath.row].name + "  " + serach_data[indexPath.row].id 
    } 
    else if tableView == self.visit_listview 
    { 
     print("second listview") 
     cell.textLabel?.text = all_vist_data[indexPath.row].date 
    } 

    return cell 
} 

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{ 
    if tableView == self.pat_search_listview 
    { 
     //--- Item at index from pat_search_listview 
    } 
    else if tableView == self.visit_listview 
    { 
     print("second listview") 
     //--- Item at index from visit_listview 
    } 
} 
+0

ありがとう、私にあなたのサポートやアイデアを与えるために –

+0

ようこそ..... :) –

関連する問題