TableView内的collectionView reloaddata

时间:2020-04-09 09:45:34

标签: swift

我需要reloadData collectionView。因为我在函数中附加到数组。为此,我需要重新加载数据,但是出现错误“表达式类型不明确,没有更多上下文”。似乎没有添加数据,因为我没有reloadData。如何使用collectionView.reloadData?如何在TableView和CollectionView上重新加载数据?

class denemeView: UIViewController, UITableViewDataSource, UITableViewDelegate {

    var davetiyeKategori = [String]()
    var davetiyeKatIsım = [String]()
    var storedOffsets = [Int: CGFloat]()

    func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? {
           return kategoriIsımYeni[section]
       }

     func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return kategoriIsımYeni.count
    }

     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

        let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)

                return cell
    }

     func tableView(_ tableView: UITableView, willDisplay cell: UITableViewCell, forRowAt indexPath: IndexPath) {

        guard let tableViewCell = cell as? CategoryRow else { return }

        tableViewCell.setCollectionViewDataSourceDelegate(self, forRow: indexPath.row)
        tableViewCell.collectionViewOffset = storedOffsets[indexPath.row] ?? 0
    }

     func tableView(_ tableView: UITableView, didEndDisplaying cell: UITableViewCell, forRowAt indexPath: IndexPath) {

        guard let tableViewCell = cell as? CategoryRow else { return }

        storedOffsets[indexPath.row] = tableViewCell.collectionViewOffset

    }
    func collectionReloadData(){
        DispatchQueue.main.async(execute: {
            self.collectionView.reloadData()
        })
    }

  override func viewDidLoad() {
           super.viewDidLoad()
        davetiyeKategoriBul()
    }


 @objc func davetiyeKategoriBul(){
     if let baslik = try JSONSerialization.jsonObject(with: data, options: []) as? [[String: Any]] {
                        for review in baslik {
                          if let soru_baslik = review["ISIM"] as? String {
                             let s = String(describing: soru_baslik)
                                self.kategoriIsımYeni.append(s)
                                           DispatchQueue.main.async {
                                                //  self.tableViewKategoriler.reloadData()
 }} }}

extension denemeView: UICollectionViewDelegate, UICollectionViewDataSource {
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return model[collectionView.tag].count
    }

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "Cell", for: indexPath) as! anaSayfaCell

        let rowValue = model[collectionView.tag][indexPath.item]
             print("urlNew", rowValue)

                   let urlNew = URL(string: (rowValue))
                   cell.denemeImage.sd_setImage(with: urlNew)
       // cell.backgroundColor = model[collectionView.tag][indexPath.item]
print("model[collectionView.tag][indexPath.item]", model[collectionView.tag][indexPath.item])
        return cell
    }

    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        print("Collection view at row \(collectionView.tag) selected index path \(indexPath)")
    }
}

0 个答案:

没有答案
相关问题