Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

为什么列表没任何展示呢?纳闷了 #2

Closed
ETmanwenhan opened this issue Nov 20, 2017 · 4 comments
Closed

为什么列表没任何展示呢?纳闷了 #2

ETmanwenhan opened this issue Nov 20, 2017 · 4 comments

Comments

@ETmanwenhan
Copy link

ETmanwenhan commented Nov 20, 2017

我的代码如下,但是列表就是没有数据展示?实在不解

class ViewController: UIViewController{
    
    var viewModel : MyViewModel? = MyViewModel()
    let disposeBag = DisposeBag()
    
    var tableView : UITableView! = {
        
       var tableView = UITableView(frame: UIScreen.main.bounds, style: .plain)
        tableView.rowHeight     = 44.0
        tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
        tableView.tableFooterView = UIView()
     
        return tableView
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        
        view.addSubview(tableView)
      
        
        self.viewModel?
            .homeAction?
            .execute(())
            .bind(to: tableView.rx.items(cellIdentifier: "cell", cellType: UITableViewCell.self)){
                index, model, cell in

                cell.textLabel?.text = model.nick_name
            }
            //.disposed(by:disposeBag)
        
    }


   var homeAction: Action<Void, [BaseUser]>?
    let model = Model()
    var data: [BaseUser]?
    
    init() {
        
        initialize()
    }
    
    
    func initialize() {
        
        homeAction = Action<Void, [BaseUser]>.init(workFactory: {[unowned self] in
            
            var params : Dictionary<String, Any> = [:]
            params["lp"]            = ""
            params["page"]          = "1"
            params["age_min"]       = "-1"
            params["age_max"]       = "-1"
            params["height_min"]    = "-1"
            params["height_max"]    = "-1"
            params["prov"]          = ""
            params["city"]          = ""
            params["user_id"]       = "1"
            
            
           return self.model.request(UserAPI.homeList(params), Msg<BaseUser>.self)
                    .debug()
                    .map{$0.list ?? []}
                    .do(onNext: {
                        self.data = $0
                    })
        })
@JianweiWangs
Copy link
Owner

do onNext里面顺利回调了么?

@ETmanwenhan
Copy link
Author

@JianweiWangs
原来是我删除了 MVVM/Model/RxMoya/MoyaProvider+Rx.swift 文件,导致请求网络后没正常响应。
我发现Moya/RxSwift 下也要一个相同名字的文件。这两个文件不是一样的吗?

@JianweiWangs
Copy link
Owner

不是一样的,这个在Moya下也是一个isuess,主要是moya对象自身是否需要被持有的问题,我有意覆盖掉了,诸如你这种情况直接用Moya的就会发生请求序列的dispose。

@ETmanwenhan
Copy link
Author

明白,谢谢

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants