以下在iPhone 6S Plus中运行不佳。 在预期的iPhone 5s中运行。 它只是一个示例Code.It也有同样的问题。
行:
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
{
return 5
}
内容:5个细胞
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
var RetCell = UITableViewCell()
if(indexPath.row == 0)
{
let cell = self.HomeTableView.dequeueReusableCellWithIdentifier("Banner" ,forIndexPath: indexPath)
RetCell = cell
}
else if(indexPath.row == 1)
{
let cell = self.HomeTableView.dequeueReusableCellWithIdentifier("Offer",forIndexPath: indexPath)
RetCell = cell
}
else if(indexPath.row == 3)
{
let cell = self.HomeTableView.dequeueReusableCellWithIdentifier("Category",forIndexPath: indexPath)
RetCell = cell
}
else if(indexPath.row == 2)
{
let cell = self.HomeTableView.dequeueReusableCellWithIdentifier("Products",forIndexPath: indexPath)
RetCell = cell
}
else if(indexPath.row == 4)
{
let cell = self.HomeTableView.dequeueReusableCellWithIdentifier("Recent",forIndexPath: indexPath)
RetCell = cell
}
return RetCell
}
显示单元格:
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
print(indexPath.row)
if(indexPath.row == 2){
guard let tableViewCell = cell as? ProductsTableViewCell else { return }
tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
}
if(indexPath.row == 4){
guard let tableViewCell = cell as? RecentViewsTableViewCell else { return }
tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
}
}
相同类别的扩展名:
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cellColl = collectionView.dequeueReusableCellWithReuseIdentifier("ProductCollection", forIndexPath: indexPath)
return cellColl
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return 5
}
在TableViewCells中:ProductsTableViewCell和其他Cell包含Extension
中的以下代码func setCollectionViewDataSourceDelegate<D: protocol<UICollectionViewDataSource, UICollectionViewDelegate>>(dataSourceDelegate: D, forRow row: Int) {
CollectionView.delegate = dataSourceDelegate
CollectionView.dataSource = dataSourceDelegate
CollectionView.tag = row
CollectionView.setContentOffset(CollectionView.contentOffset, animated:false) // Stops collection view if it was scrolling.
CollectionView.reloadData()
}
var collectionViewOffset: CGFloat {
set {
CollectionView.contentOffset.x = newValue
}
get {
return CollectionView.contentOffset.x
}
}