开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜