我有一个两行的UITableView。第一行有 UITextfield,第二行有 UICollectionView。重新加载 UITableView 时,UI 视图单元格的单元格不会出现。但是在滚动UITableView时,UICollectionView的所有单元格都变得可见。我可能做错了什么。
if indexPath.row == 0 {
let cellIdentifier = "NewPostCell"
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? NewPostCell
if (cell == nil) {
cell = Utils.getCellForGivenIdentifier(cellIdentifier, cellIdentifier: cellIdentifier, ownerT: self) as? NewPostCell
}
cell?.txtPost.delegate = self
cell?.txtPost.text = userThoughts
newPostCell = cell
return cell!
} else {
let cellIdentifier = "ASAttachmentCell"
var cell = tableView.dequeueReusableCellWithIdentifier(cellIdentifier) as? ASAttachmentCell
if (cell == nil) {
cell = Utils.getCellForGivenIdentifier(cellIdentifier, cellIdentifier: cellIdentifier, ownerT: self) as? ASAttachmentCell
}
if let height = cell?.collectionAttachment?.contentSize.height
{
cell?.cntCollectionHeight.constant = height
}
attachmentCell = cell
return cell!
}
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
if indexPath.row == 1 {
attachmentCell = cell as? ASAttachmentCell
attachmentCell?.attachmentCollection(self)
}
}
尝试将代码精确地放入设置集合视图数据源的部分,也是:
collectionView.reloadData()
这很可能是因为您在后台线程上调用tableView.reloadData()
。因此,当您实际开始滚动时,UI 将在主线程上更新,一切看起来都会正常。尝试在主线程上调用重新加载。
dispatch_async(dispatch_get_main_queue()){
self.tableView.reloadData()
}