Objective C equivalent to javascripts setTimeout?

The performSelector: family has its limitations. Here is the closest setTimeout equivalent: dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, NSEC_PER_SEC * 0.5); dispatch_after(delay, dispatch_get_main_queue(), ^(void){ // do work in the UI thread here }); EDIT: A couple of projects that provide syntactic sugar and the ability to cancel execution (clearTimeout): https://github.com/Spaceman-Labs/Dispatch-Cancel https://gist.github.com/zwaldowski/955123

UIProgressView and Custom Track and Progress Images (iOS 5 properties)

Here’s what’s going on: The images you provide to the UIProgressView are basically being shoved in to UIImageViews, and the UIImageView is stretching the image to fill the space. If you simply do: [progressView setTrackImage:[UIImage imageNamed:@”track.png”]]; Then you’re going to get weird results, because it’s trying to stretch a 10px wide image to fill (for … Read more

How to detect touches on UIImageView of UITableViewCell object in the UITableViewCellStyleSubtitle style

In your cellForRowAtIndexPath method add this code cell.imageView.userInteractionEnabled = YES; cell.imageView.tag = indexPath.row; UITapGestureRecognizer *tapped = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(myFunction:)]; tapped.numberOfTapsRequired = 1; [cell.imageView addGestureRecognizer:tapped]; [tapped release]; And then to check which imageView was clicked, check the flag in selector method -(void)myFunction :(id) sender { UITapGestureRecognizer *gesture = (UITapGestureRecognizer *) sender; NSLog(@”Tag = %d”, gesture.view.tag); … Read more

How do I animate MKAnnotationView drop?

One problem with the code above by Anna Karenina is that it doesn’t deal with when you add annotations below where the user is looking at the moment. Those annotations will float in mid-air before dropping because they are moved into the user’s visible map rect. Another is that it also drops the user location … Read more

Changing the UIBackButtonItem title

I’ve had success by creating my own UIBarButtonItem instead of setting the title of the existing one: UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithTitle:@”Back” style:UIBarButtonItemStylePlain target:nil action:nil]; self.navigationItem.backBarButtonItem = backButton; [backButton release];

How to figure out the font size of a UILabel when -adjustsFontSizeToFitWidth is set to YES?

I’m not sure if this is entirely accurate, but it should be pretty close, hopefully. It may not take truncated strings into account, or the height of the label, but that’s something you might be able to do manually. The method – (CGSize)sizeWithFont:(UIFont *)font minFontSize:(CGFloat)minFontSize actualFontSize:(CGFloat *)actualFontSize forWidth:(CGFloat)width lineBreakMode:(UILineBreakMode)lineBreakMode will return the text size, and … Read more

tech