Я студент iOS dev, и я пытаюсь контролировать табличное представление в ячейке просмотра коллекции, которая возвращает 3 (или более) таблицы, поэтому я могу иметь несколько табличных представлений. Я верю, что все реализовано правильно, но данные не возвращаются в отдельные таблицы. Я установил идентификаторы повторного использования в ячейках прототипов в tableview, а также делегат и источник данных установлены в VC.Table View не возвращает данные
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
}
Вот мой редактор проектов, чтобы быть более четким.
Компилятор не знает, что один из ваших случаев if всегда будет правдой, даже если вы знаете. Вам нужно что-то вернуть в случае, когда оба 'tableView == tableView1' и' tableView == tableview2' являются ложными или изменяют второй 'else if ...', чтобы быть просто 'else' – dan
, вы имеете в виду несколько таблиц просматривать ячейки вместо табличных просмотров? – MShah
Нет, не я, я возвращаю 2 ячейки просмотра коллекции прямо сейчас, которые представляют 2 вида таблиц, которые будут представлять разные данные. – Hightower98