2016-04-28 20 views
1

2行のUITableViewがあります。最初の行にはUITextFieldがあり、2行目にはUICollectionViewがあります。 UITableViewをリロードすると、UICollectionViewCellのセルは表示されません。しかし、UITableViewをスクロールすると、UICollectionViewのすべてのセルが表示されます。私が何をしているかも間違っている。リロードUITableViewにUITableViewCellの可視性の問題があります

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) 
      } 
    } 
+0

同じことがデバイスシミュレータと実デバイスの両方で発生しましたか? –

+0

はいデバイスとシミュレータの両方で動作しています –

+0

cellforrowattheindexpathとcollectionViewデータソースについていくつかのコードを記述できますか? –

答えて

0

まさにあなたもコレクションビューのデータソースを設定する部分に、あなたのコードに配置しようとすると:

collectionView.reloadData() 
0

あなたがバックグラウンドスレッドでtableView.reloadData()を呼び出しているので、これが最も可能性が高いです。したがって、実際にスクロールを開始すると、UIがメインスレッドで更新され、すべてが正常に見えます。メインスレッドでリロードを呼び出してみてください。

dispatch_async(dispatch_get_main_queue()){ 
    self.tableView.reloadData() 
} 
+0

私はメインスレッドでそれをやっています –

関連する問題