开发者

iOS How to Send string Class 1 to Class2 [closed]

开发者 https://www.devze.com 2023-03-08 17:24 出处:网络
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical andcannot be reasonably answered in its current form. For help clari
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the开发者_JAVA百科 help center. Closed 11 years ago.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消