Installing iPhone SDK on a PPC
Submitted by alanduncan on Sat, 12/06/2008 - 16:50It really bugs me that in order to develop applications for the iPhone, I would have to shell out thousands of dollars for an Intel Mac when I have a perfectly functional G5 dual-core desktop.
So, here are explicit instructions for getting the SDK to install on a Power PC. I can't promise this is generalizable to every PPC. I have a Power Mac G5 2.0 GHz dual. Model identifier PowerMac11,2
So, I downloaded the SDK, opened the packages folder. I double-click installed each of the packages that started with iPhone (iPhoneDocumentation.pkg --> iPhoneSystemComponents.pkg) This will install the necessary components in /Platforms
Scrolling a UIView when a UIKeyboard appears
Submitted by alanduncan on Wed, 10/29/2008 - 19:00Sometimes when a UIKeyboard appears, it covers up the view; so you need move the view automatically when it appears and disappears. Here's how:
in the UIViewController's loadView method, register for a UIKeyboardWillShowNotification:
- (void)loadView
{
[super loadView];
// lots of code here...etc.etc.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:self.view.window];
}
Then create the handler for this notification:
NSArray vs NSMutableArray for storing strings
Submitted by alanduncan on Sun, 10/26/2008 - 16:43This works:
NSArray *anArray = [NSArray arrayWithObjects:@"cat", @"pencil",@"ball",nil];
but this doesn't:
NSArray *anArray = [NSArray arrayWithObjects:@"cat", @"pencil",@"ball"];
Remember to ternimate the declaration with a nil. See the documentation:
Parameters
firstObj, ...
A comma-separated list of objects ending with nil
NSNotifications for inter-class messaging
Submitted by alanduncan on Fri, 10/24/2008 - 22:23With more complex applications, even well-constructed root controller models aren't sufficient to handle inter-class messaging. NSNotifications are helpful for such messaging. Here's a brief example:
SettingsViewController has a UISegmentedControl whose action is:
Preventing the iPhone from sleeping
Submitted by alanduncan on Fri, 10/17/2008 - 18:54While writing a timer-type application, I needed to stop the device from sleeping. Otherwise, in an application such as this, where the user doesn't touch the device for long periods of time, it will sleep. I put this in main:
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
Memory management in Obj-C/Cocoa and Cocoa touch
Submitted by alanduncan on Thu, 10/16/2008 - 17:52This is something that confused me when I started developing in Cocoa/Objective-C. Looking at most of examples of iPhone code, the following is how good developers seemed to allocate and initiate instance objects:
FooController *myFooController = [[FooController alloc] init];
[self setClassFooController:myFooController];
[myFooController release];
It didn't seem to make intuitive sense to create a local object then release it after assignment to the class object. After all, wouldn't it be simpler to just do this, assuming that the instance variable is declared with @property (retain)?
[self setClassFooController:[[FooController alloc] init]];
In the first case, the retain count increments from 0 -> 1 in the first line, 1 -> 2 in the second line, and then back to 1 after release in the last line. In the second example, there's no corresponding release. So, if you wanted to avoid the temporary object, the second form of the code could be changed to:
[self setClassFooController:[[[FooController alloc] init] autorelease];
But there may be additional overhead for the autorelease pool, though. You could try to set the instance directly without going through the accessor method; but it's discouraged outside of class init methods.
