问题
I currently have two classes. Class A has my UIView attached to it. My second Class, Class B has some other functions that works in the background. I have one function that ends up with a string. Is there a easy way to move that string from Class B to Class A that has the UIView.
回答1:
Sure -- just make sure that the instance of B has a reference to the instance of A that you want to pass the string to.
Rule: Any time you want one object, say foo, to be able to communicate directly with another object, bar, then foo needs a pointer to bar.
Communication between objects isn't always direct -- some other object (or objects) may act as intermediaries. That doesn't change the rule above; indirect communication is just a sequence of direct communications. If foo uses a notification to communicate with bar, foo needs a pointer to the notification center, and the notification center needs a pointer to bar.
来源:https://stackoverflow.com/questions/7720933/moving-a-nsstring-to-a-uiview-from-a-different-class