Tap Status Bar Time - iphone

I am using a UITableView in my app. After scrolling down, if I tap on the status bar time, the table is repositioned to the top. Any idea how this is done and is it possible to intercept the action. TIA, Jim B

A UITableView is an extension of UIScrollView, and UITableViewDelegate is an extension of UIScrollViewDelegate.
A UIScrollViewDelegate can implement this method:
- (BOOL)scrollViewShouldScrollToTop:(UIScrollView *)scrollView
That will allow you to intercept it.
You can also just turn it off with your tableview's "scrollsToTop" property.
If you just want to know when it happens, you can use this delegate method:
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView

Related

How to get the contentOffset of a UIScrollView mid-scroll?

How would one get the contentOffset or similar information about a UIScrollView while the user is still scrolling? For example if I wanted to place an image as a header right above the content of a UIWebView, without the image being part of the WebView's scrollView, but have it update while the user scrolls, not just jumping to the position after they let go. How could I go about doing this?
In iOS 5, the UIWebView has a scrollView property which is the UIScrollView responsible for handling the scrolling. Prior to iOS 5 you can search the UIWebView's subviews property for the subview using [subview isKindOfClass:[UIScrollView class]].
Once you have the UIScrollView, you can then set its delegate property. In the delegate you can then respond to the scrollViewDidScroll: message when the user scrolls, and update the position/contents of your header view.
Added: 29/2/2012 - In order to preserve the UIWebView's functionality, you will need to forward your intercepted UIScrollViewDelegate methods to the UIWebView too. To do this, you can call the UIWebView at the end of all mandatory methods within the protocol and implement something like forwardInvocation: or forwardingTargetForSelector for the optional protocol methods. This will preserve your original UIWebView behavior and allow you to enhance it with your own logic.
Why can't you just put the header as a separate view above the UIWebView? Why does it have to be a subview?

Access UIScrollViewDelegate from subclass of UITableView

I'm working on a project where I have to work lot of with UITableViews. So, I want to detect if the table view (UIScrollView) is scrolling.
First I handled it with the UIScrollViewDelegate in the UIViewController where my UITableView is added as a subview. Now, to keep the code clean, I want to subclass UITableView and in this class I have to access to the delegate methods of UIScrollView, e.g. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView.
But how can I do this? Is it possible?
All you have to do is implement - (void)scrollViewDidScroll:(UIScrollView *)scrollView delegate & detect if the scrolling is happening in your UITableView or somewhere else.
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
if(scrollView == self.tableView)
{
//your logic here
}
return;
}
Those UIScrollViewDelegate methods must be defined in a class that is the delegate of the tableview that you want to handle scrolling changes of. If you put these methods in the implementation file of your UITableView subclass then you should set the tableview's delegate as itself:
[self setDelegate:self];
But then you also have to define your UITableViewDelegate and UITableViewDataSource methods in the UITableView subclass. This might complicate things if you want to use your UITableView subclass more than one place in your project. If I were you, I would double-think about my design and behave accordingly.

touchesEnded:withEvent: not being called from my UIView, which is on top of a UITableView

I have a UITableView and a UISearchBar in its header. When the user clicks in the UISearchBar I create a view (bg: black, alpha .65) and place it over the content in the UITableView. What I want is when the user clicks this semi transparent UIView is to resign the first responder from the UISearchBar. I have implemented touchesEnded:withEvent: in my UIViewController (is also my UITableView's controller) but this function never get called. Is there something I'm missing here?
Cheers,
Rob
Your controller will only handle events of its own view, which is probably the table view. If you want to handle touch events in the view you have added later, you need to subclass UIView and implement touchesEnded:withEvent: method.
i found a good link , may this link help you,
download the source code for further help
Building a SearchView with UISearchBar and UITableView
http://jduff.github.com/2010/03/01/building-a-searchview-with-uisearchbar-and-uitableview/
You need to use UISearchBarController insted of UISearchBar,This having builtin functionality for what you looking for.

How to intercept UIScrollView contentOffset changes from UITableView subclass?

Actually, a UITableView is a UIScrollView (inherits from that). Now, I made a UITableView subclass and added this line of code to it:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(#"contentOffset: %#", NSStringFromCGPoint(self.contentOffset));
}
For some reason this is never called when I scroll the table view. But since UITableView has a delegate property on it's own, I assume that it must implement UIScrollViewDelegate protocol and is the delegate for the scroll view itself. Isn't it?
How could I intercept scroll position changes? I want to read them only. Probably I couldn't set them with contentOffset, right?
Probably I couldn't set them with
contentOffset, right?
As UITableView inherits from UIScrollView you can get and set its contentOffset property.
Note also that UITableViewDelegate protocol is defined the following way:
#protocol UITableViewDelegate<NSObject, UIScrollViewDelegate>
That is it conforms to UIScrollViewDelegate protocol as well so your tableView's delegate(not UITableView itself) can implement any UIScrollViewDelegate methods and they should get called fine.
Just implement setContentOffset: and call super after you read the values you want. A UITableView is a UIScrollView so you can scroll it by calling setContentOffset: as well.

automatic scroll - a scroll view on Touch of textField - iPhone

I have many textfields in my Application which are in a scrollview.
What i need is when user touches on a textfield,
scrollview should scroll in such a way, so that that textfield should not be behind
the keyboard.
I've written a pretty straightforward tutorial on doing this, it mimics as much as possible the behavior of Apple own applications, if it can be of any help:
Adjust UITextField hidden behind Keyboard with UIScrollView
You can use the method - (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated in UIScrollView, this should scroll to the offset of the point you give it, you will need to figure out the offset through code
Maybe you could set the text fields' delegates to self, and then adopt the UITextFielDelegate protocol for the class, and then in this method:
- (void)textFieldDidBeginEditing:(UITextField *)textField
Make the scroll view scroll down enough so that you can see the text field.. I don't know how to make the scrollview scroll down though.
Here is a free library for keyboard handling http://www.codeproject.com/Tips/509810/Keyboard-Handling-in-iPhone-Applications. You need write just one line of code:
[AutoScroller addAutoScrollTo:scrollView];
Dont confuse with name AutoScroller. Purpose is same what you asked.