i have two controller
in view1.h i have
NSString *bg;
@interface Lottery5ViewController : UIViewController {...}
in view2.m i have
-(IBAction) switchView2{
self.bg = @"blueButton.png";
}
but it cannot compile and said
request for member ‘bg’ in something not a structure or union
i just want to modify the value of a variable in view1 from view2
Your problem is that in
view2‘sswitchView2method you are callingselfand trying to change an ivar (or property, not sure which it is from the code shown) of a different class. If you want to send something from one instance to another you have to establish some sort of connection between them first. There are a few ways you can get them talking. The better ways to be able to pass something like this is to set up a delegate protocol or use notifications, thenview2could call the delegate method that makes the change inview1or post a notification thatview1would be registered for so that it could make the change. The less desirable way to accomplish this would be to giveview2an ivar (or property) that isview1. You would then be able to use something likeview1.bg = @"blueButton.png";.