I am using Open Source toolchain to compile my iPhone apps. So I have no Interface Builder or XCode. How would I setup the layout of widgets like UIButton, UITextView, etc. Also, how would I add an event handler to those UI widgets? Please remember that I don't have Interface Builder or XCode.
+1
A:
I suspect you're going to run into trouble eventually if you're not using Xcode. However, it is definitely possible to do everything iPhone without using Interface Builder. You just end up defining a lot of rectangles and pixel constants in your code, and calling (e.g.) addTarget to hook actions up to methods.
UIButton *myButton = [[UIButton alloc] initWithFrame:CGRectMake(MYBUTTON_X, MYBUTTON_Y, MYBUTTON_WIDTH, MYBUTTON_HEIGHT)];
[myButton addTarget:self action:@selector(foo) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:myButton];
[myButton release];
That creates a button and has it call your "foo" method when pushed. Anything that can be done in IB can be done in plain code (though it's often more tedious to do it that way.)
Mike Kale
2010-05-25 20:50:58
"I suspect you're going to run into trouble eventually if you're not using Xcode." What do you mean?
Mohit Deshpande
2010-05-25 21:07:24
I suspect this is for Objective-C 1.0. Is Objective-C already supported on the iPhone? If so, could you update your code to utilize Objective-C 2.0's [UIButton new]
Mohit Deshpande
2010-05-25 21:26:00
iPhone does support most of ObjC 2.0, but not garbage collection. The common pattern is to call +alloc and then an -init.. method, I'm not actually familiar with +new.And about Xcode -- If you're targeting a jailbroken phone then you might not need it. But if you're going to be publishing in the App Store, you're likely to run into a lot of trouble with the code signing steps if you're not using Xcode. (Or at least calling Apple tools like xcodebuild from the command line. You can use whatever you want for a text editor.)
Mike Kale
2010-05-25 21:37:00
My apps target jailbroken iPhones. Mines is jailbroken and I signed it in the terminal app with ldid -S
Mohit Deshpande
2010-05-26 02:03:59