I have Three different views on iphone. I switch between different views successfully, but I want to access the 1st view's variable in second view's ViewDidLoad method but I can't get it so plz help me on that.
+1
A:
You need a reference to the first view on the second one. So, when you instantiate the second one, implement a message that would receive the first view and store a reference to it.
Let me point that it's better to use ViewController pattern to orchestrate data and behavior flowing from one view to another.
Pablo Santa Cruz
2009-03-28 11:30:57
thanks for replay but i have done all still i cant get.
2009-03-28 11:45:01
can you provide some code? I know how to accomplish what you are trying but I don't know if it's the same path you are taking.
Pablo Santa Cruz
2009-03-28 11:59:22
ok i have posted the code of my problem
2009-03-28 12:23:16
OK. Going to take a look at it.
Pablo Santa Cruz
2009-03-28 12:32:41
+1
A:
Having two subclasses of UIView declared like so:
@interface ViewOne : UIView {
NSString *someVar;
}
@property (nonatomic, copy) NSString *someVar;
@end
@interface ViewTwo : UIView {
NSString *referenceToSomeVar;
}
@property (nonatomic, retain) NSString *referenceToSomeVar;
@end
You could do the following the reference the "someVar" variable from the first view
ViewOne *view1 = [[ViewOne alloc] init];
view1.someVar = @"This is the original variable";
ViewOne *view2 = [[ViewOne alloc] init];
view2.referenceToSomeVar = view1.someVar;
nduplessis
2009-03-28 12:25:28