HOME       >>       Programming

Xcode - Objective C 2.0


sonesay

Does anyone here use Xcode and Objective C to develop for the iPhone here? I started reading through some documents but still don't fully get the structure and syntax of the language. I couldn't find a place where I could put a stopper on the source code and run through each line like in other IDE's to get a better idea of how it works.for a simple hello world app it creates 4 filesHelloWorldAppDelegate.hHelloWorldAppDelegate.mMyViewController.hMyViewController.mHelloWorldAppDelegate.h

#import <UIKit/UIKit.h>@class MyViewController;@interface HelloWorldAppDelegate : NSObject <UIApplicationDelegate> { IBOutlet UIWindow *window; MyViewController *myViewController;}@property (nonatomic, retain) UIWindow *window;@property (nonatomic, retain) MyViewController *myViewController;@end

HelloWorldAppDelegate.m

#import "HelloWorldAppDelegate.h"#import "MyViewController.h"@implementation HelloWorldAppDelegate@synthesize window;@synthesize myViewController;- (void)applicationDidFinishLaunching:(UIApplication *)application { // Set up the view controller MyViewController *aViewController = [[MyViewController alloc] initWithNibName:@"HelloWorld" bundle:[NSBundle mainBundle]]; self.myViewController = aViewController; [aViewController release]; // Add the view controller's view as a subview of the window UIView *controllersView = [myViewController view]; [window addSubview:controllersView]; [window makeKeyAndVisible];}- (void)dealloc { [myViewController release]; [window release]; [super dealloc];}@end

MyViewController.h

#import <UIKit/UIKit.h>@interface MyViewController : UIViewController <UITextFieldDelegate> { IBOutlet UITextField *textField; IBOutlet UILabel *label; NSString *string;}@property (nonatomic, retain) UITextField *textField;@property (nonatomic, retain) UILabel *label;@property (nonatomic, copy) NSString *string;- (IBAction)changeGreeting:(id)sender;@end

MyViewController.m

#import "MyViewController.h"@implementation MyViewController@synthesize textField;@synthesize label;@synthesize string;- (IBAction)changeGreeting:(id)sender { // Set our model value -- it's not used anywhere else at the moment, but it illustrates the principle self.string = textField.text; NSString *nameString = string; // If the user entered an empty string, set the name string to "World" if ([nameString length] == 0) { nameString = @"World"; } // Create a new string for the label NSString *greeting = [[NSString alloc ] initWithFormat:@"Hello, %@!", nameString]; label.text = greeting; /* The greeting string was created with 'alloc', so to adhere to memory managment conventions, now release it. It's the label's responsibility to take ownership of the greeting string when its text is set. */ [greeting release];}- (BOOL)textFieldShouldReturn:(UITextField *)theTextField { // When the user presses return, take focus away from the text field so that the keyboard is dismissed. if (theTextField == textField) { [textField resignFirstResponder]; } return YES;}- (void)dealloc { // To adhere to memory management rules, release the instance variables. [string release]; [textField release]; [label release]; [super dealloc];}@end

Thats basically it 4 files but there is a bug when run in the iPhone simulator I don't know what the cause is. Can anyone explain what file is run first and whats called etc. I still have no idea what one of the four files are executed first.


iGuest

heres what you need to doXcode - Objective C 2.0

if you don't know c learn it, if you do buy a book called Programming in Objective-C and read it from cover to cover, it will teach you everything you need to know. Then go to youtube and watch some tutorials on xcode and the interfacebuilder. That will get you on your feet for xcode, once you FULLY understand xcode and interfacebuilder and how they work then look up some iPhone sdk tutorials, this will give you the basics on how iPhone apps are built

-reply by giggly kisses

 



VIEW DESKTOP VERSION REGISTERGET FREE HOSTING

Xisto.com offers Free Web Hosting to its Members for their participation in this Community. We moderate all content posted here but we cannot warrant full correctness of all content. While using this site, you agree to have read and accepted our terms of use, cookie and privacy policy. Copyright 2001-2019 by Xisto Corporation. All Rights Reserved.