问题描述
我目前有两节课。 A级附有我的UIView。我的第二课,B课有一些其他功能在后台工作。我有一个函数,最后是一个字符串。是否有一种简单的方法可以将该字符串从B类移动到具有UIView的A类。
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.
推荐答案
当然 - 只需制作确保B的实例具有对要传递字符串的A实例的引用。
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.
规则:只要你想要一个对象,比如说 foo
,就可以直接与另一个对象进行通信, bar
,然后 foo
需要指向栏
的指针。
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
.
对象之间的通信并不总是直接的 - 一些其他对象(或对象)可以充当中介。这不会改变上面的规则;间接通信只是一系列直接通信。如果 foo
使用通知与栏
进行通信, foo
需要一个指向通知中心的指针,通知中心需要一个指向 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
.
这篇关于将NSString从另一个类移动到UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!