Class1 i have
textClass1 = @"Hello"
how to send String to Class2
Label.text = textClass1 ?
Thank you :D
In your Class1.H set a protocol
:
@protocol Class_1_Delegate
@optional
- (void) ASimpleFunction:(NSString*)val;
@end
in any class where do you want to get the value, add delegate (in the .H) like this:
@interface Class2 : UIViewController <Class_1_Delegate> { }
Now, implement in Class2.M your
- (void) ASimpleFunction:(NSString*)val {
}
and remember to set delegate for class1!
class1.delegate = self
(class2)
it's all!
Now, you are able to call ASimpleFunction
from any classes that implements your protocols!
If you don't like this way, see NSNotifications
from apple docs.
hope this helps.
精彩评论