I'm adding a timer in every cell and every cell has its own time, API send me the expire time to alarm the user i need to play timer on the expire time for every specific cell, i'm facing problem when i scroll the table view and it deque the cell then timer does not work properly, And how i can handle it for those cells which are not present on the screen. suppose my array has 100 items but at the time i can show only 10 item on screen then how i'll check and alarm the user for 20th or 30th cell (item).
And how i check alarm for every single cell. Please explain it.
i've tried with indexPath but its not helpful for me for those cells which are not on screen and making issue on scroll.
You should try to set timer in Model. if you are work on Model-View-ViewModel...second update your elapse time when your app will come form background state(if your app doesn't support background modes)
Related
I want to fetch the amount of times a cell in a tableview has been viewed when it is completely in the view. That should only happen when it is completely in the view, minor parts of top and bottom cells shouldn't count.
And after a certain amount of time(~3 sec) has passed, it should trigger a function of print "hello".
I tried creating a timer and scheduling it in willDisplay method and invalidating it in didEndDisplayingCell method. It somehow takes into consideration the cells which are not fully in the view.
Also tried tableView.visibleCells and iterating cells in tableView.indexPathsForVisibleRows but nothing helped.
Any Help on this would be much appreciated.
Cheers!
While you want to keep track of how long a cell is displaying for (and the number of times it's been displayed), you don't actually want to keep these numbers in your custom (subclassed) UITableViewCell, because these cells get recycled and reused very quickly as they are scrolled on and offscreen.
Whatever your datasource object is, you should add a property (or two) to it to keep track of when the object is displayed in a cell (i.e. a "var displayCount : Int" property?), and you can start a Timer (or NSTimer) to count X seconds before displaying your "Hello" message.
You can detect whether a cell is fully visible via the methods found in the answers to this related question, which is when you can start up your Timer.
To detect when the cell is scrolled offscreen (so you can increment the display count and/or cancel the timer), use the delegate method didEndDisplayingCell.
I'm showing Countdown timer in my Tableview cells for every product, having limited time offers.
As i scroll my tableview the values of timer are reflected to other cells. I know it is due to reuse of table view cells.
I want to show countdown timer for each product which are continuously changing for each product.
Any help will be appreciated.
Thanks in advance
You need to add observer in awakeFromNib() of your custom tableview cell class with a target function which update your UI of the cell. Then you need to declare a NSTimer variable inside your ViewController with target function which post the notification in regular intervals .You can set the initial values in cellForRowAtIndexPath method of the tableview.
I have a timer that insert a new item on a tableview every 2 seconds, it is required that the tableview shows this new line insertion with an animation of 1 second, the problem is that the user interaction is blocked while the tableview insert animation is happening, I tryied to pass as option for the animation the constant UIViewAnimationOptions.AllowUserInteraction, but it did not worked. What I need is that the user can interact with the tableview, selecting cells, scrolling etc even during the animation sequence. Any ideias ? The code for the problem example is on github
https://github.com/munhra/TableAnimationProblem
This video shows the not desired behavior
https://www.youtube.com/watch?v=Jb7dnCv5wXw&feature=youtu.be
I have an app with custom calendar constructed from a UICollectionView. When I load a month for the calendar, I'd like to pre-load the previous and next months so that I can quickly swipe forward or back without delay.
Right now there's a delay in loading the next or previous months after swiping, and in instruments a lot of the delay is attributed to the UICollectionView cellForItemAtIndexPath method.
Is there a way to force that method to run without showing the view controller? I need to do that for the previous and next months and that should reduce the transition time by about 400ms.
Possible? Thanks for your time
I have a timer on multiple cell which updates every second. how can i implement NSTimer scheduledTimerWithTimeInterval in each cell. Is it possible to use single Timer which keeps track of the time of each cell. How can i implement this?.
Since the table view cells are made up of UI elements, I don't believe you can have dynamic timers as such. However, you could reload the table view every second, and you could set the timer to the appropriate value in each cell when reconfiguring the cells (which will happen after a call to [tableView reloadData]).