#objc_setAssociatedObject
Explore tagged Tumblr posts
objectivesea · 12 years ago
Link
So I wrote a pretty cool addition to DMAFWebViewController.
If you set webViewController.webView.footerView to a UIView, the view will be placed inside the webView's scroll view below all the web content. If the web content changes size (because a page loads) the footer will be pushed below the web content.
I think this may be a novel way of doing this. Googling around for a way to add a footer to UIWebView I found UIWebView with Header and Footer which uses javascript calls to ask the webview how large its content is.
I also used objc_setAssociatedObject to store the content size. You need to remember the last contentSize because you need to adjust the contentSize in order to make room for the footer. You'd get infinite recursion if you didn't watch for this. The reality is I could easily have used a property to do this, I was just keen to try out the whole associatedObject thing.
The above linked commit details all the changes needed to make this happen.
EDIT: Pages that are shorter than the UIWebView's frame don't trigger a contentSize change. Adding this to layoutSubviews fixes the issue by triggering one manually the first time layoutSubviews is called:
if (!objc_getAssociatedObject(self.scrollView, "associated_height")) { NSValue *value = [NSValue valueWithCGSize:self.scrollView.contentSize]; [self observeValueForKeyPath:@"contentSize" ofObject:self.scrollView change:@{NSKeyValueChangeNewKey : value} context:nil]; }
See this commit for the change in action.
2 notes · View notes
abdusdotme-blog · 12 years ago
Link
Call back blocks are not part of UIAlertView. We need add this functionality to UIAlertView. For this create Category of UIAlertView class that conforms UIAlertViewProtocol. In this category we will add a method that receives completion handler block. (To add methods/functionality to an existing class best practice is to make category of that class. Any methods declared in a category will be available to all instances of the original class). Following would be the steps:
Create Category of UIAlertView say as (AddBlockCallBacks)
Make a reference to store completion handler block in [Continue Reading...]
0 notes