Skip to main content

Posts

Showing posts with the label cocoa

Does UIGestureRecognizer work on a UIWebView?

I am attempting to get a UIGestureRecognizer working with a UIWebview which is a subview of a UIScrollView. This sounds odd but when I have the numberOfTouchesRequired set to 2 the selector fires, but when numberOfTouchesRequired is set to one the selector doesn't fire.

How to handle app URLs in a UIWebView?

I recently found that my UIWebView was choking on ITMS links. Specifically, from the UIWebView in my app, if I navigate to a site such as this one and click the "Available on the App Store" link, UIWebView would error out with "Error Domain=WebKitErrorDomain Code=101 The URL can't be shown." After a bit of Googling, I realized that I needed to catch requests for app links and have iOS handle them. I started out by looking to see if the scheme starts with "itms" in -webView:shouldStartLoadWithRequest:navigationType: , but realized that there might be other kinds of app links that the system can handle. So I came up with this, instead: - (void)webView:(UIWebView *)wv didFailLoadWithError:(NSError *)error { // Give iOS a chance to open it. NSURL *url = [NSURL URLWithString:[error.userInfo objectForKey:@"NSErrorFailingURLStringKey"]]; if ([error.domain isEqual:@"WebKitErrorDomain"] && error.code == 101

Is there a way to make drawRect work right NOW?

The original question............................................... If you are an advanced user of drawRect on your ipop*, you will know that of course drawRect will not actually run until "all processing is finished." setNeedsDisplay flags a view as invalidated and the OS, in a word, waits until all processing is done. This can be infuriating in the common situation where you want to have: a view controller 1 starts some function 2 which incrementally 3 creates a more and more complicated artwork and 4 at each step, you setNeedsDisplay (wrong!) 5 until all the work is done 6 Of course, when you do that, all that happens is that drawRect is run once only after step 6. What you want is for the ^&£@%$@ view to be refreshed at point 5. This can lead to you smashing your ipops on the floor, scanning Stackoverflow for hours, screaming at the kids more than necessary about the dangers of crossing the street, etc etc. What

Why tack a protocol of NSObject to a protocol implementation

I have been seeing some code around that resembles the following: @protocol MyProtocol <NSObject> // write some methods. @end Is there any particular reason why MyProtocol conforms to the NSObject protocol? Isn't that rather redundant in that if you do something such as: id <MyProtocol> foo; // foo here conforms to NSObject AND MyProtocol? Just curious what the logic is. Source: Tips4all

NSLog with CGPoint data

I have a CGPoint called point that is being assigned a touch: UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; I want to get the x coordinate value into my console log: NSLog(@"x: %s", point.x); When I use this, log output for this is: x: (null) I have verified that point is not null when this is called using the debugger and variable watch. Any help appreciated, Thanks // :)

Key-Value-Observation &mdash; Looking for a more elegant solution to respond to value changes

I've run into a frustrating feature of KVO: all notifications are funneled through a single method ( observeValueForKeyPath:.... ), requiring a bunch of IF statements if the object is observing numerous properties. The ideal solution would be to pass a method as an argument to the method that establishes the observing in the first place, but it seems this isn't possible. Does a solution exist to this problem? I initially considered using the keyPath argument ( addObserver:forKeyPath:options:context: ) to call a method via NSSelectorFromString , but then I came across the post KVO Dispatcher pattern with Method as context and the article it linked to which offers a different solution in order to pass arguments along as well (although I haven't gotten that working yet). I know a lot of people have come up against this issue. Has a standard way of handling it emerged?

iPhone Development w/ xCode 3.2.4

I just bought the book: Sams Teach Yourself iPhone Application Development in 24 Hours. In the book it uses xCode 3.2.4, so I went ahead and tried xCode 4.3 (the current version), but I didn't understand what to do... I then found this page... https://developer.apple.com/downloads/index.action I downloaded the version of xCode used in the book (just so I could see the same thing the book shows). But, I'm getting two errors each having something to do with the Interface Builder... "This version of Interface Builder does not support documents of type "Interface Builder Cocoa Touch Document (XIB 3.x)" targeting "iPhone/iPod touch"." And it comes up twice for two different documents in my xCode project. How can i get it to work? In the book the code I put in works just fine. Also my Mac Version is: 10.7.3

Return Value of method using AsiHTTPRequest

I have a class that uses AsiHTTPRequest. I want to make a method like this: -(NSData*)downloadImageFrom: (NSString*)urlString; { // Set reponse data to nil for this request in the dictionary NSMutableData *responseData = [[NSMutableData alloc] init]; [responseDataForUrl setValue:responseData forKey:urlString]; // Make the request NSURL *url = [NSURL URLWithString:urlString]; ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url]; [responseDataForUrl setValue:responseData forKey:[request url]]; [request setDelegate:self]; [request startAsynchronous]; // Wait until request is finished (???? Polling ?????) // while(responsedata = nil) { // do nothing // } BAD SOLUTION return responseData; } After that. A delegate method is called when the responseData is ready. Is there a better solution to continue, than doing polling in the variable responseData?