I'm new to Xcode and I'm having some trouble with finishing my say hello script.

Joined
Mar 13, 2012
Messages
8
Reaction score
0
Points
1
So I need some help finishing this script that I started working on in xcode 4.5.2

It's a simple say hello script for the iphone that I'm working on., it's supposed to say hello. How ever I'm having problems with the source code in viewcontroller .m. Every time I try these codes

_displayLabel.text = @"hello world"
_label.text = @"hello world"

None of them work.. Can any one help?
 
OP
R
Joined
Mar 13, 2012
Messages
8
Reaction score
0
Points
1
Hey if I've worded any thing funny, it's because I'm really new to this all. I could really use some help none the less.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Post all of the code you have so far, and someone might be able to help you.

Regards Mark
 
OP
R
Joined
Mar 13, 2012
Messages
8
Reaction score
0
Points
1
//
// ViewController.m
// hello world
//
// Created by DEEPseaDIVER on 11/21/12.
// Copyright (c) 2012 DEEPseaDIVER. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)startpressed:(id)sender {
}
@end
 

Raz0rEdge

Well-known member
Staff member
Moderator
Joined
Jul 17, 2009
Messages
15,762
Reaction score
2,100
Points
113
Location
MA
Your Mac's Specs
2022 Mac Studio M1 Max, 2023 M2 MBA
Where are you IBOutlets to get access to the labels? Did you hook up a button to the IBAction "startpressed"??
 
OP
R
Joined
Mar 13, 2012
Messages
8
Reaction score
0
Points
1
Where are you IBOutlets to get access to the labels? Did you hook up a button to the IBAction "startpressed"??

I don't think I put a Iboutlet in, the video I watched did not have this info. And yes the IBAction is hooked up to the startpressed button.
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
Firstly you posted iOS code in the OSX forum, this does matter as to assign text to a NSTextField control in an Mac project, is different to assigning text to a UITextField in an iOS project.

Secondly you listed this code in your first post.
_displayLabel.text = @"hello world"
_label.text = @"hello world"

But in your next posting you've put some code for a View Controller Implementation class that does not show the above code in it, you've not shown the interface .h file for the same View Controller .m class file.

So you have not posted all of the code, so it is hard for us to help you.

But as RazOrEdge has pointed out, you have to have IBOutlets linked for the Text Fields in your Interface Builder xib file, if you dont have these IBOutlets, you cannot assign text to the Text Field controls.

For Example

Code:
// .h file

@interface myClass : NSObject
{
    IBOutlet UITextField *myTextField;
}

@property (nonatomic, readonly, strong)IBOutlet UITextField *myOtherTextField;

@end

// .m file

@implementation myClass

@synthesize myOtherTextField;

- (id)init
{
    self = [super init];

    if (self) {
        myTextField.text = @"Hello";
        myOtherTextField.text = @"World";
    }
    return self;
{

@end

In the above sudo code, I would have to link the two IBOutlets to the Text Fields in my Interface xib file, if I dont, then the text would not appear in the Text Fields.

Lastly I noticed your using dot notation in your code, which I have also done, but you should consider using Objective-C style coding, using square braces like this.

Code:
[myTextField setText: @"Hello"];

the reason for this is as you start to deal with more Cocoa Touch Framework classes, some
of there Methods are only accessible with this type of syntax.

Hope this is of some help, but unless you post all of the relevant code from your project, we will not be able to help you more.

Regards Mark
 
OP
R
Joined
Mar 13, 2012
Messages
8
Reaction score
0
Points
1
]
Firstly you posted iOS code in the OSX forum, this does matter as to assign text to a NSTextField control in an Mac project, is different to assigning text to a UITextField in an iOS project.

Secondly you listed this code in your first post.
_displayLabel.text = @"hello world"
_label.text = @"hello world"

But in your next posting you've put some code for a View Controller Implementation class that does not show the above code in it, you've not shown the interface .h file for the same View Controller .m class file.

So you have not posted all of the code, so it is hard for us to help you.

But as RazOrEdge has pointed out, you have to have IBOutlets linked for the Text Fields in your Interface Builder xib file, if you dont have these IBOutlets, you cannot assign text to the Text Field controls.

For Example

Code:
// .h file

@interface myClass : NSObject
{
    IBOutlet UITextField *myTextField;
}

@property (nonatomic, readonly, strong)IBOutlet UITextField *myOtherTextField;

@end

// .m file

@implementation myClass

@synthesize myOtherTextField;

- (id)init
{
    self = [super init];

    if (self) {
        myTextField.text = @"Hello";
        myOtherTextField.text = @"World";
    }
    return self;
{

@end
In the above sudo code, I would have to link the two IBOutlets to the Text Fields in my Interface xib file, if I dont, then the text would not appear in the Text Fields.

Lastly I noticed your using dot notation in your code, which I have also done, but you should consider using Objective-C style coding, using square braces like this.

Code:
[myTextField setText: @"Hello"];
the reason for this is as you start to deal with more Cocoa Touch Framework classes, some
of there Methods are only accessible with this type of syntax.

Hope this is of some help, but unless you post all of the relevant code from your project, we will not be able to help you more.

Regards Mark


Alright thanks for correcting me mark this info is really helping a lot, here's the rest of the file.

.h below

//
// AppDelegate.h
// hello world
//
// Created by DEEPseaDIVER on 11/21/12.
// Copyright (c) 2012 DEEPseaDIVER. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end


.m below were the tutorial video said the code should be


//
// ViewController.m
// hello world
//
// Created by DEEPseaDIVER on 11/21/12.
// Copyright (c) 2012 DEEPseaDIVER. All rights reserved.
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

- (IBAction)startpressed:(id)sender {
_displayLabel.text = @"hello world"
}
@end


If I screwed any thing up please don't hesitate to correct me. :D
 
Joined
Aug 13, 2011
Messages
200
Reaction score
7
Points
18
Location
West Sussex
The code you have posted could not possibly be all of the code, because you have an AppDelegate.h interface file, but no matching AppDelegate.m implementation file, you need to have both for a complete class object.

Also you have posted a ViewController.m implementation file, but no corresponding ViewController.h interface file, again you would need both to make a complete ViewController class, as in the generic code I posted above.

I dont know which training video you are learning from, but my advice would be find alternative resources to learn from.
It seems that you do not understand the basics of the Objective-C language, so I would advise you to stop where you are and learn that first before attempting to write an iOS app, this book below is a good start to learn the language first.

Objective-C Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides): Aaron Hillegass: 9780321706287: Amazon.com: Books

After learning the Objective-C language, you can then move on to learn App development with the Xcode tools, with one of these books below.

Cocoa Programming for Mac OS X (4th Edition): Aaron Hillegass, Adam Preble: 9780321774088: Amazon.com: Books

iOS Programming: The Big Nerd Ranch Guide (3rd Edition) (Big Nerd Ranch Guides): Joe Conway, Aaron Hillegass: 9780321821522: Amazon.com: Books

In short, your going to have to start at the begining, and take your time, there is no short cut to learn app development, it takes a long time, and hard work.

I could write your code for you, but that would teach you nothing, and it would also leave you with no basic understanding of what and how the code works, so take my advise and get yourself some good books to learn from.

Regards Mark
 
OP
R
Joined
Mar 13, 2012
Messages
8
Reaction score
0
Points
1
The code you have posted could not possibly be all of the code, because you have an AppDelegate.h interface file, but no matching AppDelegate.m implementation file, you need to have both for a complete class object.

Also you have posted a ViewController.m implementation file, but no corresponding ViewController.h interface file, again you would need both to make a complete ViewController class, as in the generic code I posted above.

I dont know which training video you are learning from, but my advice would be find alternative resources to learn from.
It seems that you do not understand the basics of the Objective-C language, so I would advise you to stop where you are and learn that first before attempting to write an iOS app, this book below is a good start to learn the language first.

Objective-C Programming: The Big Nerd Ranch Guide (Big Nerd Ranch Guides): Aaron Hillegass: 9780321706287: Amazon.com: Books

After learning the Objective-C language, you can then move on to learn App development with the Xcode tools, with one of these books below.

Cocoa Programming for Mac OS X (4th Edition): Aaron Hillegass, Adam Preble: 9780321774088: Amazon.com: Books

iOS Programming: The Big Nerd Ranch Guide (3rd Edition) (Big Nerd Ranch Guides): Joe Conway, Aaron Hillegass: 9780321821522: Amazon.com: Books

In short, your going to have to start at the begining, and take your time, there is no short cut to learn app development, it takes a long time, and hard work.

I could write your code for you, but that would teach you nothing, and it would also leave you with no basic understanding of what and how the code works, so take my advise and get yourself some good books to learn from.

Regards Mark

I understand I guess the video I was learning from really wasn't that great. half the things you're telling me the video did not touch on so I will read more about this. Thanks again mark for sticking around and leading me through this, while I am a little disappointed I would never ask you or any one to write the code for me. The whole purpose of this post besides trying to finish my project was to learn, and I learned a lot.

Thanks again guys!
 

Shop Amazon


Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.
Top