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

cwm1021

macrumors newbie
Original poster
Dec 22, 2010
7
0
Hello Guys

The program is basically like this in a nutshell:

===================================

There is a UIViewController, it has an instance variable of NSInteger:


I declare it in the UIViewController .h file as:

NSInterger *theNum;
...
@property NSInteger *theNum;

Then, I synthesize it in its .m file:

@synthesize theNum;

The view (UIView) of this UIViewController has a method doSomething: needs to access the value of theNum.

Here is the code in this "view"'s .m file:

-(void)doSomething {

NSInteger *myNum = self.superview.theNum; //error: request for member 'theNum' in something not a structure or union

// do something

}

==============================

So how can I get the value of theNum from UIViewController to its UIView?
:confused:

Thanks for advanced! And wish you guys Merry Xmas. :)
 
Last edited:

cnstoll

macrumors 6502
Aug 29, 2010
254
0
It shouldn't work like that. Your "ViewController" should have a method that some how modifies "The View".

Your "ViewController" can access it's property with:
Code:
self.theNum

If your "view" needs a variable from your "ViewController" then you should pass that variable from the ViewController when you create the "view" object.

View Controller Programming Guide

A little more information about what you're trying to do would be helpful.
 
Last edited:

flummoxed

macrumors member
Nov 27, 2010
38
0
Yes. Your subclassed UIView definition cannot be aware of the existence to the viewController variable.

You need to add an NSInteger instance variable and property to your UIView subclass.

Then when you create the instance of the subclass in the viewController code
you can pass the value between the properties.

Code:
my_uiview.number = self.number;
"self" being the viewController since you are implementing this code in the viewController.

This has to be done outside your UIView instance method, before you call the method. The my_uiview.number variable is referenced inside your UIView method, but the value is passed between them outside.

You could also pass the viewController number as an argument to the UIView method.
Code:
- (void)doSomething:(NSInteger*) a_number{
 //do something with the number
}

Then the call to the UIView method in the viewController would look like this...
Code:
[my_uiview doSomething:self.number];

I hope that is correct. I'm new to this as well.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.