let officialAccountObservable : Observable<[SearchUser]> = SearchAPI.sharedAPI.suggestAccounts() officialAccountObservable.bind(to: tableView.rx.items(cellIdentifier: "followcell",cellType: FollowCell.self)) { (index,user,cell) in if user.profileImagePath.isEmpty == false { cell.profile.af_setImage(withURL: URL.init(string: user.profileImagePath)!) }else { cell.profile.image = UIImage.init(named: "icon_user_03") } cell.nickName.text = user.nickName cell.follow.rx.tap .debounce(0.3,scheduler: MainScheduler.instance) .subscribe(onNext: { [unowned self] in cell.setFollow(user: user,completion: { (result) in if(result == true){ } }) }).addDisposableTo(self.disposeBag) }.addDisposableTo(disposeBag) func suggestAccounts() -> Observable<[SearchUser]> { let uri = Constants.VyrlSearchURL.suggestUsers return Observable.create { observer in let request = Alamofire.request(uri,method: .get,parameters: nil,encoding: JSONEncoding.default,headers: Constants.VyrlAPIConstants.getHeader()).responseArray { (response: DataResponse<[SearchUser]>) in let value = response.result.value observer.onNext(value!) observer.onCompleted() } return Disposables.create(with: request.cancel) } }
我想在代码中重新加载表视图(result == true)
对于重新加载,必须收到OfficialAccountObservable.
我的代码已经全部结束,我想知道如何在该状态下更新它.
解决方法
AFAIK,这是这样做的标准方式 –
let source = PublishSubject<Observable<[SearchUser]>>() let officialAccountObservable: Observable<[SearchUser]> = source.switchLatest() source.onNext(suggestAccounts()) // every call will refresh your table