1

I'm using RxSwift, RxCocoa for my app and implemented a tableView.
When It got priceData from viewModel for tableView, it showed full list of priceData.

But I want to show only 50 counts at the first time and show more when I scroll it.
Without RxSwift/RxCocoa, I used numberOfRowsInSection for paging of tableView.

But I don't know how I can use this with RxSwift

Here is my code. what should I do with my code for making to pageable tableView?

viewModel.priceData         
            .drive(tableView.rx.items(cellIdentifier: "Cell")) { (index: Int, list, cell: Cell) in
...
}.disposed(by: disposeBag)
  • The simplest way, that I see, it just appends data to `priceData` trough kind of command for example `viewModel.loadMore()`. `loadMore() { priceData.append(... here append data after 50th index...) }` and call this method on the end of data in `UITableView`. But I believe there can be a much smarter way to do this. Option if you need a fast way to do it. – Andrew Mar 13 '20 at 15:07
  • Yes I think your suggestion can be the solution for me too. I’ve tried to figure out the way but there isn’t the clear answer... – User17373928 Mar 15 '20 at 14:27

1 Answers1

1

The RxDataSources library allows you to section your data. Add it to your project and you can use sections.

Daniel T.
  • 32,821
  • 6
  • 50
  • 72
  • Thank you for letting me know to use RxDataSources. So I implemented RxDataSources and made TableView successfully. However, I don't know how to control numberOfRowInSection... – User17373928 Mar 15 '20 at 05:12
  • The library "controls" it for you automatically. – Daniel T. Mar 15 '20 at 11:44
  • Do you mean I don’t need to set NumberOfRowsInSection? – User17373928 Mar 15 '20 at 14:20
  • Yes, that's what I mean. – Daniel T. Mar 15 '20 at 19:29
  • No..I mean I wanted to show only 50 rows at the first time. For example if Array has 10000items, I want to show only 50 items at the first time. And I want to show 50 items more when tableView’s scroll reach to end or almost end. So the first time rows count is 50 and then(when scroll reachs to end) 100, 150... I could do it without RxSwift... Without RxSwift, I used scrollView’s offset for paging in scrollViewDidScroll method. – User17373928 Mar 15 '20 at 22:58
  • 1
    The solution is to only put 50 items in the source observable until the user scrolls to the bottom, then emit 100 items... I don't know what any of this has to do with numberOfRowsInSection though. – Daniel T. Mar 15 '20 at 23:46
  • I thought that way too. I just wondered there is another way to do this..thank you for helping me :) – User17373928 Mar 15 '20 at 23:55
  • This might be helpful: https://gist.github.com/danielt1263/10bc5eb821c752ad45f281c6f4e3034b – Daniel T. Mar 15 '20 at 23:56
  • Thank you! I think I can refer it :-) Thank you again! – User17373928 Mar 16 '20 at 01:34