Moving a NSString to a UIView from a different class

岁酱吖の 提交于 2019-12-11 19:06:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!