views:

772

answers:

2

I have a UITableview that I would like to scroll to the top when the status bar is touched.

I expected to find a notification that I could listen to and then use tableview:scrollToRowAtIndexPath: for the scroll, but can find none.

Is there a way to do this?

[Update]

Finding some more on the net, I am suspicious that this is the simulator biting me. My UIScrollView is failing to scroll to the top in the simulator, but I have not tried on hardware. Also, I have one UIScrollView, but also UITextView, so I wonder if that is eating it.

I will see what I can do with scrollsToTop.

+4  A: 

This article on cocoawithlove.com is exactly what you want.

From that article:

"The trickiest part of the sample application is detecting a touch in the status bar.

By implementing a custom setContentOffset:animated: method on a UITableView and setting a breakpoint in that method, you can see in the debugger stack that the UIApplication sendEvent: method is invoked for status bar touches, so that's where we'll begin."

Kriem
No longer works.
Max Seelemann
@ Max Seelemann - Too bad. :(
Kriem
+1  A: 

It should be happening automatically unless you set the scrollsToTop property to NO.

Chris Lundie
True. But, there can only be one scrollView with scrollsToTop set as YES. Catching a touch in order to do other fancy stuff besides the scrollView scrolling to the top isn't possible that way. But I agree with you that setScrollsToTop:YES is the simplest solution. :)
Kriem
Good point. In the original question it didn't look like you needed to do anything fancy.
Chris Lundie