Tag: cocoa touch

Why do Xcode templates have #imports that duplicate Prefix.pch?

While learning iPhone programming, every Xcode template I’ve seen includes an AppName-Prefix.pch file with the following contents: #ifdef __OBJC__ #import <Foundation/Foundation.h> #import <UIKit/UIKit.h> #endif My understanding is that this file’s contents are prefixed to each of the source code files before compilation. Yet each of the other files also imports UIKit, which seems superfluous. For […]

Combining a UILongPressGestureRecognizer with a UIPanGestureRecognizer

I d’like to combine a UILongPressGestureRecognizer with a UIPanGestureRecognizer. The UIPanGestureRecognizer should start with a long press. Is there a simple way to do this? or do I really have to write my own gesture recognizer? I wan’t something like on the home screen. You press on an icon and after some time the icons […]

navigationItem.backBarButtonItem not working? Why is the previous menu still showing as the button?

Trying to customize my back button in a drilldown navigation controller. On my one view controller I have an Add button where the code programatically generates a new UIViewController: – (void)add:(id)sender { MyAddViewController *addController = [[MyAddViewController alloc] initWithNibName:@”MyAddViewController” bundle:nil]; [self.navigationController pushViewController:addController animated:YES]; [addController release]; } This works and when I click the add button it […]

UITableView, make footer stay at bottom of screen?

This question already has an answer here: tableFooterView property doesn't fix the footer at the bottom of the table view 9 answers

Convert int to shortened, formatted string

The user will enter a dollar value as an int, and I’d like to convert the result into a shortened, formatted string. So if the user enters 1700, the string would say “$1.7k”. If the user enters 32600000, the string would say “$32.6m”. Update Here’s the code I have so far. It seems to be […]

Reverse Geocode Current Location

Is it possible to reverse Geocode your current location on SDK 3.x? I need to simply get the zip code of the current location. The only examples I’ve seen use CoreLocation which I dont think was introduced until SDK 4.

Should I subclass the NSMutableArray class

I have an NSMutableArray object that I want to add custom methods to. I tried subclassing NSMutableArray but then I get an error saying “method only defined for abstract class” when trying to get the number of objects with the count method. Why is the count method not inherited? I read somewhere else that I […]

C function calling objective C functions

I’ve a c function in my viewController.m. int abc(int a, char* b) { //do something } I also have a function -(void) callIncomingClass { UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect]; //set the position of the button button.frame = CGRectMake(100, 170, 100, 30); //set the button’s title [button setTitle:@”Click Me!” forState:UIControlStateNormal]; //add the button to the view […]

How to add a time interval to an NSDate?

I have an NSDate and a duration. I need to get the time after the duration Given: The date is “2010-02-24 12:30:00 -1000” duration is 3600 secs I need to get “2010-02-24 13:30:00 -1000” I thought dateWithTimeIntervalSinceReferenceDate:, would do the trick but I see now that this gives a date offset from 1 Jan 2001 […]

AVAudioPlayer turns off iPod – how to work around?

I use AVAudioPlayer to play sounds in my app, but it turns off the iPod when a sound plays. Is there a way to prevent this? I don’t want to use System Sounds because I can’t control their volume. Thanks for your help.