2016-07-27 9 views
3

私は学生ですが、私は複数のテーブルビューを持つことができるように3(またはそれ以上)のテーブルビューを返すコレクションビューのセルでテーブルビューを制御しようとしています。私はすべてを正しく実装したと信じていますが、データは個々のテーブルビューに返されません。テーブルビューのプロトタイプセルにリユース識別子を設定し、デリゲートとデータソースもVCに設定されています。テーブルビューでデータが返されない

var tableView1: UITableView? 
var tableview2: UITableView? 


    // MARK: - Table view data source 

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    if tableView == tableView1 { 

     return 2; 

    } else if tableView == tableview2 { 

     return 3 
    } 
    return 0; 

} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    if tableView == tableView1 { 
     return 2; 

    } else if tableView == tableview2 { 

     return 1; 
    } 
    return 0; 

} 



func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
    var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) 
    if tableView == tableView1 { 
     cell = tableView.dequeueReusableCellWithIdentifier("testcell1", forIndexPath: indexPath) as! UITableViewCell 

    } else if tableView == tableview2 { 

     cell = tableView.dequeueReusableCellWithIdentifier("testcell2", forIndexPath: indexPath) as! UITableViewCell 
    } 

    // Configure the cell... 
    if tableView == tableView1 { 

    cell.textLabel?.text = "Homeroom" 
    cell.detailTextLabel?.text = "8:15 AM - 9:00 AM" 
    cell.selectionStyle = .None 

    } else if tableView == tableview2 { 
     cell.textLabel?.text = "Test Table 2 " 
     cell.detailTextLabel?.text = "1:30 PM - 2:30 PM" 
     cell.selectionStyle = .None 

    } 

    return cell 

} 


//**Center collection cells in the middle** 

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets { 
    let sideInset = (collectionView.frame.size.width - 650)/2 
    return UIEdgeInsets(top: 0, left: sideInset, bottom: 0, right: sideInset) 
} 

} 

//Card Scrolling datasource 

extension SAHomeViewController: UICollectionViewDataSource { 

func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 
    return 1 
} 

    //Number of cards on home screen 
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 
    return 2 
} 

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cardcell", forIndexPath: indexPath) 

    // Configure collection view cell 

    return cell 
} 

ここは私のプロジェクトエディタです。

enter image description here

+0

コンパイラは、わかっていても、あなたのif caseの1つが常に真であることを知りません。 'tableView == tableView1'と' tableView == tableview2'の両方がfalseの場合に何かを返す必要があります。あるいは、else if ...を 'else'に変更する – dan

+0

あなたは複数のテーブルを意味しますか?テーブルビューの代わりにセルを表示しますか? – MShah

+0

いいえセルはありません、私は現在、2つのコレクションビューセルを返しています。異なるデータを表示する2つのテーブルビューを表します。 – Hightower98

答えて

2

あなたは両方の機能にデフォルトの戻り値を提供する必要があります。コンパイラが必要とされる関数がIntの値を返すようにチェックする必要があり、これらの関数で条件が一致しない場合は何も返されません。

func numberOfSectionsInTableView(tableView: UITableView) -> Int { 
    // #warning Incomplete implementation, return the number of sections 
    if tableView == tableView1 {    
     return 2;    
    } 
    else if tableView == tableview2 
    {    
     return 3; 
    } 
    return 0; // here 
} 

func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    // #warning Incomplete implementation, return the number of rows 
    if tableView == tableView1 { 
     return 2;    
    } else if tableView == tableview2 {    
     return 1; 
    } 
    return 0; // here 
} 
関連する問題