Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

KiranPanesar

macrumors newbie
Original poster
Mar 25, 2011
10
0
Hello everyone!

First up, I'm new here (both the forum and to iPhone programming), so be nice!

Now, on with the problem I have.

I am working on an task manger/to-do application for iOS, and I could use a hand:

Firstly, how would I go about creating a new UI object (such as a label) for each new task (i.e., when a button is pressed in a different .xib, a new label is created for the task on the main screen of the app, showing the name of the task).

Also, I am having some issues regarding accessibility of variables/objects:

I have separate .xib, .m and .h files for both the main screen and the 'Add Task' screen. I couldn't access the outlet I used for the text field on the 'Add Task' field when setting label's text in the main screen (in order to test whether I could set the text to a pre-made label).

I hope you can help a n00b out!

Thanks,
Kiran.
 
Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5)

Welcome to MR!

For us to really be able to help you we need more info. Here's something I told another poster recently.

Tell us more about what your background is, what resources (books, websites, courses) you are using, where you are going with this, ...

These two resources are (IMHO) very useful to read before you ask a question on a programming forum that can help you format a question in a way that will be more effective than casting a wide net.

http://www.mikeash.com/getting_answers.html
http://whathaveyoutried.com

Don't ask open questions or withhold pertinent information, provide code where possible, say what you expect, what you got instead, give an example of another app that does what you want, ...

B
 
Wirelessly posted (Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_3 like Mac OS X; en-us) AppleWebKit/533.17.9 (KHTML, like Gecko) Version/5.0.2 Mobile/8F190 Safari/6533.18.5)

For us to really be able to help you we need more info...
Tell us more about what your background is, what resources (books, websites, courses) you are using, where you are going with this, ...

B

Thanks for the reply and warm welcome.

I've read a book on Objective-C and one on iPhone development. I've been programming in Objective-C for about a year now and using Cocoa Touch for a few months. I've also (unfortunately) used Visual Basic for just over a year for the odd piece of work. But I'm still quite an amateur!

As for what resources I'm using to help me along with this, it's nothing really. I'm pretty much doing this by myself. But I am referencing the two aforementioned books and Google/YouTube when I get stuck.

Here is a sample piece of code which shows the accessibility issue:

In SwitchrViewController.h (the main view of my application):
Code:
@interface SwitchrViewController : UIViewController {
    IBOutlet UILabel *taskOne;
}

@property (nonatomic, retain) UILabel *taskOne;

Then, in SecondViewController.m:

Code:
#import "SecondViewController.h"
#import "SwitchrViewController.h"

@implementation SecondViewController

@synthesize taskName;

-(IBAction)saveNewTask:(id)sender {
    NSString *taskNameString = [[NSString alloc] initWithFormat:taskName.text];
    taskOne = taskNameString;
}

On the line,
Code:
taskOne = taskNameString;
I am getting an error, "Use of undeclared identifier 'taskOne'".

I was hoping that we could tackle this, more fundamental problem first?

Thanks again,
Kiran
 
As an Amazon Associate, MacRumors earns a commission from qualifying purchases made through links in this post.
On the line,
Code:
taskOne = taskNameString;
I am getting an error, "Use of undeclared identifier 'taskOne'".
On the left you have a UILabel, on the right an NSString.

Have you tried:

Code:
taskOne.text = taskNameString;

or

Code:
[taskOne setText:taskNameString];

B
 
On the left you have a UILabel, on the right an NSString.

Have you tried:

Code:
taskOne.text = taskNameString;
Yup, no luck.

or

Code:
[taskOne setText:taskNameString];
Still no luck.

It doesn't appear to be an issue with the command I'm using to set the text, it's accessing the outlet that seems to be causing the error.

Thanks again,
Kiran
 
It doesn't appear to be an issue with the command I'm using to set the text, it's accessing the outlet that seems to be causing the error.
You have another problem I hadn't noticed at the first glance.

Your @property is for taskOne while your @synthesize is for taskName. You then use the text property of taskName (which does not seem to be defined in your .h file) to load into taskOne via taskNameString.

What are you actually trying to do? Access the value of the text property of a UILabel (as an NSString) or set one?

Which thing (textName or textOne) is your UILabel and property of the ViewController and which is an NSString?

Either you simply mangled the code when you extracted it for this example or you need to keep better accounting of what's what.

B
 
Your @property is for taskOne while your @synthesize is for taskName. You then use the text property of taskName (which does not seem to be defined in your .h file) to load into taskOne via taskNameString.
B

taskOne is the label used to present the task's name, it's declared in SwitchrViewController.h and synthesized in SwitchrViewController.m (not shown in my provided extract).

It will get it's text value from the text box, taskName (declared in SecondViewController.h and synthesized in SecondViewController.m).

I first tried using something along the lines of:
Code:
taskOne.Text = taskName.Text;

I.e., directly taking the text input in the text box and setting it as the name. This didn't work, so I tried creating an NSString object to act as a bridge.

It might be easier for you to take a look at this little project I made which presents the issue (attached to this post). I always feel it's easier to solve the problem when you can get 'hands-on' with the code.

Hope you can help and thanks for everything thus far.
Kiran
 

Attachments

  • Switchr.zip
    32.8 KB · Views: 135
You have two separate view controller classes: SwitchrViewController and SecondViewController. The first creates and shows an instance of the second, but there is no other connection between the two instances.

You have to design the view controllers so they share a common model (which doesn't exist at all in your code). You need to design a model, views, and controllers that all work together. You can't just make up the code as you go.

Frankly, this isn't a design. It's not really even the beginning of a design. It's just two view controllers.

If this is your first app, you should pick something simpler, such as an app that has only one view controller.

If this isn't your first app, then describe what other apps you've written, even if they were apps from a tutorial. We need to get a sense of what you've done, and what other programs you've completed.

The only sense I get so far is that you're already in over your head. You don't seem to realize what the error is coming from, how to correct it, or why you can't access one class's instance variables from an other unrelated class. Those are all fundamental things, which any book should teach you upon completion.
 
The only other iOS applications I've written have been from tutorials/books. The most elaborate one was from the book I'm using to learn iOS development and was a flash card application. It had a view controller for the main screen and one to create flash cards. There was then a class to store all of the flash card objects in.

I think I'll go back to both the Objective-C/Cocoa Touch books I own to try and become more knowledgable about interaction between different view controllers.

Thanks,
Kiran/.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.