Nov 8, 2009

Xcode - Objective C 2.0

free web hosting
Open Discussion > MODERATED AREA > Computers > Programming Languages > Others

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 files

HelloWorldAppDelegate.h
HelloWorldAppDelegate.m
MyViewController.h
MyViewController.m

HelloWorldAppDelegate.h
CODE

#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
CODE

#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
CODE

#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
CODE

#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.

 

 

 


Comment/Reply (w/o sign-up)

(G)giggly kisses
heres what you need to do
Xcode - 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

 


Comment/Reply (w/o sign-up)



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

This textarea will convert to Rich-Text automatically (IE, Firefox, Chrome)

Similar Topics

Keywords : Xcode Objective 20


    Looking for xcode, objective, c, 2, 0

Searching Video's for xcode, objective, c, 2, 0
See Also,
advertisement


Xcode - Objective C 2.0

Affordable Web Hosting, Low cost Web Hosting - ComputingHost.com