Nav Link On

iPhone Dev Forums > General Development > SDK Coding Help > SDK Expert help required

Reply

 

LinkBack Thread Tools Display Modes
Old 07-04-2009, 12:24 AM   #1 (permalink)
Junior Member
Default Avatar
 
Join Date: Jul 2009
Posts: 4
Default SDK Expert help required

Hi there,

I am fairly new to iPhone development and Objective-C. Having one of those late nights where you just cant work out a solution to a problem and wondered if anyone could help?

I have developed an app with 2 buttons. Within the method for one of the buttons I have assigned a value to a variable (NSDate dteInception). I am keen to use this variable (and the assigned value) within the method for the second button.

Can anyone provide tips/advice/solution on how this can be done?

Cheers,

Charlie
charlieuk1977 is offline   Reply With Quote
Old 07-04-2009, 02:41 AM   #2 (permalink)
Administrator
 
MarkHernandez's Avatar
 
Join Date: Mar 2008
Location: San Diego, CA
Posts: 508
Default

Hi Charlie,

Yeah, you need to get a fundamental understanding of instance variables and how you access their values. When you understand them, then you realize you can ask your "self" for the value of one of your variables, or ask any other object (including the application object) for the value of it's instance variable.

This is an important concept to understand before proceeding, and has to do the the model-view-controller separation of values (model), the user interface (view) and the application logic (controller).

Look in the Apple documentation and the must-have book Beginning iPhone Development for the following terms
model-view-controller
instance variable
self
properties (dot notation and accessors)
It's easier to understand than you think.

Also, don't forget to watch the introductory videos from both Apple and the Stanford iPhone development videos for easy-to-understand explanations that start talking about Objective-C. In fact, I'd do that first. Evan Doll of Stanford does a great job of explaining things in the third video of the set.

If you already know a bunch of this stuff, I apologize. But rather than give specific answers, I believe it's more important to have a solid understanding of how things work instead. But that's me.

Mark
MarkHernandez is offline   Reply With Quote
Old 07-04-2009, 08:17 AM   #3 (permalink)
Junior Member
Default Avatar
 
Join Date: Jul 2009
Posts: 4
Default

Mark,

Thank you for the comments and the useful references. Will get straight onto it,

Many thanks!

Charlie
charlieuk1977 is offline   Reply With Quote
Old 07-04-2009, 09:45 AM   #4 (permalink)
Junior Member
Default Avatar
 
Join Date: Jul 2009
Posts: 4
Default

Mark (or anyone else?),

While I am downloading all the beginner videos, could anyone suggest what code I could write to resolve this issue:

In the .m file, I have 2 buttons and create an instance variable within one of the methods. How can I then use that instance variable within the second method?

Quote:

- (IBAction)buttonOne
{
...

NSDate *dteInception = [NSDATE dateWithString: strIncManInput];

...
}

- (IBAction)buttonTwo
{
...

NSTimeInterval tmiTimeInterval = [dteInception timeIntervalSinceNow];

...
}
This code errors, since the dteInception variable was given a value within the first button method, but the assigned value is not know within the second button method. How can I pass the variable value across?

Mark - I am following your training guide, but is it possible you could provide any pointers on this exact example (I have looked into "self" and am not sure if this is correct or if I should be using @public)?

Cheers,

Charlie
charlieuk1977 is offline   Reply With Quote
Old 07-05-2009, 07:07 AM   #5 (permalink)
Junior Member
Default Avatar
 
Join Date: Jul 2009
Posts: 4
Default

Sorry forgot to mention that the variable I am trying to set within one method and then reuse its assigned value in the other method, is called: dteInception.

Cheers,

Charlie
charlieuk1977 is offline   Reply With Quote
Reply

iPhone Dev Forums > General Development > SDK Coding Help


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0 RC1