使用RxSwift重新加载Tableview [英] Reload Tableview using RxSwift

查看:851
本文介绍了使用RxSwift重新加载Tableview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用RxSwift进行tableview。每次从api获取数据后我都需要重新加载我的表但是我没有这样做。我找不到任何解决方案。有人可以帮忙吗?

I am using RxSwift for tableview. I need to reload my table each time after getting data from api but I'm failed to do this. I couldn't find any solution for that. Can anybody help?

我有一个从Api的响应获得的地方数组。我已经在视图中使用了这个代码加载了,但是当数组没有被调用时已更新。

I have an array of places obtain from response of an Api.I have used this code in view did load, but its is not being called when array is updated.

推荐答案

我发现了这个问题。我的阵列没有正确更新。我做了以下更改。

I have found the issue. My array was not being getting updated correctly. I did the following changes.

声明 dataSource ModelClass的变量:

Declare dataSource variable of ModelClass:

let dataSource = Variable<[SearchResult]>([])

现在将它与表格视图绑定为空:

Bind it with the table view right now it is empty:

dataSource.asObservable().bindTo(ResultsTable.rx.items(cellIdentifier: "SearchCell")){ row,Searchplace,cell in
    if let C_cell = cell as? SearchTableViewCell{
        C_cell.LocationLabel.text = Searchplace.place
    }
}.addDisposableTo(disposeBag)

然后将包含searchPlaces的更新数组存储在其中:

Then store my updated array in it that contains the searchPlaces:

dataSource.value = self.array

现在,每次更改dataSource的值时,都会重新加载表格视图。

Now each time when value of dataSource will be changed, table view will be reloaded.

这篇关于使用RxSwift重新加载Tableview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆