3
저는 학생용 iOS 개발자이며, 여러 테이블 뷰를 가질 수 있도록 3 개 이상의 테이블 뷰를 반환하는 콜렉션 뷰 셀에서 테이블 뷰를 제어하려고합니다. 나는 모든 것을 올바르게 구현했다고 믿지만 데이터가 개별 tableviews로 리턴된다. 나는 테이블 뷰의 프로토 타입 셀에 reuseidentifier를 설정했고 delegate와 datasource는 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
}
내 프로젝트 편집자는 다음과 같습니다.
컴파일러는 사용자가 알고있는 경우에도 if case 중 하나가 항상 true가 될지 여부를 알지 못합니다. 'tableView == tableView1'과'tableView == tableview2'가 모두 false 인 경우에 뭔가를 돌려 주거나 두번째'else if ... '를'else'로 변경해야합니다. – dan
다중 테이블을 의미합니까? tableviews 대신 셀보기? – MShah
아니요 셀이 없습니다. 다른 데이터를 표시 할 2 개의 테이블 뷰를 나타내는 2 개의 콜렉션 뷰 셀을 반환합니다. – Hightower98