Entries Tagged 'iPhone Apps' ↓

iPhone How to: UItextField Value to Show Float with Zeros

To have a UILabel print out a price float with 2 decimal places you'll want to cast a string with to except a float with 2 decimal places.

myFloatLabel.text = [NSString stringWithFormat:@"$%3.2f", [self.floatValue floatValue]];

No Access to iPhone running OS 3.0.1 though XCode Organizer

After updating the iPhone in iTunes to Software OS 3.0.1 I was unable to access it through the xcode organizer. After reinstalling the newest xocde (failed) and some digging I found a line of code you need to copy and paste into your terminal once, restart xcode, and you have access to pushing onto the iphone again.

Open up Terminal, copy below, paste and enter into terminal, restart xcode.

ln -s /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0\ \(7A341\) /Developer/Platforms/iPhoneOS.platform/DeviceSupport/3.0.1

iPhone SDK CoreData Debugging Error 1560 & 1570

One of my CoreData applications started acting buggy, and was spitting out a huge error dump on app close in the debug console. The errors spitting out didn't tell me anything but CoreData Error 1560 and 1570. Upon inspection I found on google that another layer of errors is stored in the CoreData foundation. On Stack OverFlow found a very useful function but re-wrote it because

![[survey managedObjectContext] save:&error]

was causing an error.

Add this into you applicationWillTerminate function in your Application Delegate

/**
 applicationWillTerminate: saves changes in the application's managed object context before the application terminates.
 */

- (void)applicationWillTerminate:(UIApplication *)application {
       
        NSError* error;
        if(![[self managedObjectContext] save:&error]) {
                NSLog(@"Failed to save to data store: %@", [error localizedDescription]);
                NSArray* detailedErrors = [[error userInfo] objectForKey:NSDetailedErrorsKey];
                if(detailedErrors != nil && [detailedErrors count] > 0) {
                        for(NSError* detailedError in detailedErrors) {
                                NSLog(@"  DetailedError: %@", [detailedError userInfo]);
                        }
                }
                else {
                        NSLog(@"  %@", [error userInfo]);
                }
        }
       
}

The original post can be found here

The cause of Error in my CoreData Application was an Attribute in my xcdatamodel file. An optional field was checked as indexed and not optional. The simple action of unchecking indexed and checking optional fixed a whole mass of errors.
CoreData Error

How to Add a Home Navigation Button to the iPhone NavigationController

A quite useful button for a navigation controller with a deep stack would be a home button. It is simple to add.

In your RootViewController viewDidLoad Function

- (void)viewDidLoad {
    [super viewDidLoad];
    UIBarButtonItem *homeButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Home", @"")       style:UIBarButtonItemStyleBordered  target:self action:@selector(goHome:)] autorelease];
    self.navigationItem.rightBarButtonItem = homeButton;
}

That will add a home button in to top right of your navigation controller

Create a function called go home in your rootViewController

// return to root view
- (void)goHome:(id) sender {  
   [self.navigationController popToRootViewControllerAnimated:YES];
}

This function will pop your view controller to its root view

Why Develop iPhone Apps with PNGs

PNG's kick ass, that being said, sometimes JPGs are smaller when compressed. Below is an except from Addison Wesley's iphone cook book.

"Xcode automatically optimizes your PNG images using the pngcrush utility shipped with the SDK. (You’ll find the program in the iPhoneOS platform folders in /Developer. Run it  from the command line with the –iphoneswitch to convert standard PNG files to iPhone- formatted ones.) For this reason,use PNG images in your iPhone apps where possible as your preferred image format."

Now go batch resize your image catalogs into PNG format, now. :)