The title says multiple button presses, but actually I’m looking to stack multiple events. I have a chat application that can receive many chat messages at once. In my messageReceived function, I would like to scroll to the bottom of the most recent chats. The problem I’m having is that sometimes many messages (50+) can come in at the same time. I’ve determined that scrolling to the bottom is a huge performance bottle neck if performed 50 times, but works great if only performed after messages are received.
I’d like scroll to the bottom after a delay, say 0.1 seconds, in my messageReceived function. But I’d like all new chat messages that occur within this 0.1 seconds to “stack”, and only issue a single scroll to bottom request.
I think that a system of setting and canceling timers would work for this, however I can’t get it right. Is there a better way to make this happen! thanks!
If you are setting your delayed “scroll to the bottom” request with something like
then you can use a cancel command like
then the only time your
scrollToBottom:gets called is when it doesn’t get cancelled (so, the last time in the bunch). Now you don’t need a timer.