Skate-glass-test_small Eric White 10 posts

Yes, i know, sorry, but can you help a brother out with sending variables between UIviews?

I have found bits and pieces of things here and there, but in the end nothing seems to work completely. Mostly because I should be programming my 6809 Coco not my iPhone.

So, how do you make global variables that can be seen from anywhere (even from outer space, which I find myself quite often now in xcode?)

or

How do you pass simple values between UIViews?

Thanks for all the fishes.

http://studiodrive.com

 
Photo_13_small Bill Dudney 372 posts

Hey Eric,

Take off every Zig!

So I can’t tell for sure from your post, but I assume that you have 2 UIViewControllers that are managing 2 UIViews and you want to pass your model object from the first UIViewController to the second.

Best way to accomplish that is to have a ‘setModel:’ method on the second UIViewController that you call from the first UIViewControler just before the second UIViewController is pushed onto the nav stack.

HTH

Just sit back and let the planet dissolve around you…

 
Skate-glass-test_small Eric White 10 posts

I took off every Zig, but then i get a “NSString:Udon’tKnowWhatThe{@#}UrDoing” error…
which I can’t find listed anywhere.

I looked for the 'setModel:' magic beans and did find one reference:


// -----------------------
// setModel:value
// -----------------------

- (void)setModel:(NSData*)value
{
    [value retain];
    [model release];
    model = value;
}

Which I have decided to have a t-shirt made of, but perhaps I neglected to mention in my earlier post, I work best with “copy, paste & hope” code techniques. Which I know can be annoying to the professional programmer crowd.

You did you your super-mind-powers to see through my noobly-encoded query, for that I am impressed. Yes, I have two UIViewControllers involved in this mystery.

UIViewController1 is creating 'someVariables' that after some fancy-visual-distraction, gets flipped over (and spanked in)to UIViewController2 where I have evil plan to display 'someVariables' (hopefully more than one variable at a time) in some hopefully unreadable font.

I have read stories about the government controlled 'global.h' files with unpopular 'extern' spirited variable definitions and found mention of the elusive 'singleton' cult (or class, depending on who you talk too.) Even uncovered the wildly eastern technique of using UILabel to secretly pass notes in class without the other views seeing the truth. Alas, no matter what I find, copy and carefully paste into my iphone WMD app, all I end up with is fizzle, pop, and a random click with a handful of warnings and errors that suggest I take up golf.

I think I just got pushed onto the nav stack again.

 
Photo_13_small Bill Dudney 372 posts

:)

So you need to write a set of methods such as


- (void)setVariableOne:(NSString *)interestingBitOne {
//something like setModel above
}

one for each of the variables.

Or if you want to take it up a notch you could define a model class

- new file in Xcode choose Obj-C Class
- Name it MyInterestingModel or some such nonsense
- click the ‘I’m done’ button (Finish I think is its real name)
- that gives you a .h file and a .m file
- for each attribute do something like this


@interface MyInterestingModel : NSObject {
NSString *variableOne;
}

@property(nonatomic, retain) NSString *variableOne;

@end

and then in the .m file


@implementation MyInterestingModel
@synthesize variableOne;
@end

And to graduate from ‘the only marginally geeky because you know weird video game translations and HGTTG’ you need to grok OO programming and Obj-C. The Kochan book is good for Obj-C and probably a bit of OO as well.

Good Luck!

 
Skate-glass-test_small Eric White 10 posts

Chapter 3

After a good round of iGolf, i have finally seen the light. Your suggestion on the book “Programming in Objective-C” by Stephen Kochan was a hole-in-one!

Chapter 3 talks about Classes, Objects and Methods in a down to earthling kinda way that doesn’t expect the reader to know C or any other letter-languages. Very refreshing for us who don’t belong to the programmer class.

 
Photo_13_small Bill Dudney 372 posts

Hey Eric,

Glad it helped, you have plenty chance to survive, make your time!

 
Skate-glass-test_small Eric White 10 posts

One more thing…

Just found this and found it kinda interesting and somewhat related to my original query…

http://cocoawithlove.com/2008/11/singletons-appdelegates-and-top-level.html

7 posts, 2 voices