In general, itโs a very bad idea to reload a cell to change one element in it, not to mention its state, because, as you said, it has a lot of problems with states, animation +, this also creates a scroll problem and your re-rendering . That being said, this is by far the easiest solution. Let's try to go a little at the conceptual level of coding, as I can clearly see that you are able to code it yourself in the right direction
Controllers vs. Views
While I am on thin ice here, because there will always be people who have a different opinion about this, here is what I consider the correct use of views and controllers:
- Controllers in iOS are used to control and customize views. The controllers should not have network logic, etc., but it should interact with your model layer. He should act only as a decision maker on how to present the desired result to the user.
- Contrary to this, Views are what you need to control. There should not be any logic that works with your application model. Submissions should be written so that they are as reusable as possible, unless they have good reason for them (a very specific component, etc.). They should have methods to change the properties of this view. You should not directly access the outputs in the cell (since they can change, names, etc., but the functionality will probably remain the same - if not, then there is no difference)
- Views should contain drawing logic (it also includes fe. If you have a date format, it should be there).
Decision
So, if we establish what should be done, here is what I consider the best solution:
- Create one timer in your controller and let it work indefinitely
- Create a repository from which you will dynamically add and remove cells that interest you as you scroll and change your data.
- At each tick tick, go through the entire repository and update the cells that interest you, using the correct data, using the methods on the cell (setProgress :), which will update both progress and Lb
This solution should work even without using a GCD. The problem is that if you have too many update requests, it can basically shut up the interface and display it only occasionally or maybe never. To do this, you need to update the interface in the main thread, but it is called in async mode, for example:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), { () -> Void in dispatch_async(dispatch_get_main_queue(), { () -> Void in
source share