将NSString从另一个类移动到UIView

时间:2021-05-06 20:13:35

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.

我目前有两节课。 A级附有我的UIView。我的第二课,B课有一些其他功能在后台工作。我有一个函数,最后是一个字符串。有没有一种简单的方法可以将该字符串从B类移动到具有UIView的A类。

1 个解决方案

#1


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.

当然 - 只需确保B的实例具有对要传递字符串的A实例的引用。

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,能够直接与另一个对象bar进行通信,那么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.

对象之间的通信并不总是直接的 - 一些其他对象(或对象)可以充当中介。这不会改变上面的规则;间接通信只是一系列直接通信。如果foo使用通知与bar通信,则foo需要指向通知中心的指针,并且通知中心需要指向bar的指针。

#1


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.

当然 - 只需确保B的实例具有对要传递字符串的A实例的引用。

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,能够直接与另一个对象bar进行通信,那么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.

对象之间的通信并不总是直接的 - 一些其他对象(或对象)可以充当中介。这不会改变上面的规则;间接通信只是一系列直接通信。如果foo使用通知与bar通信,则foo需要指向通知中心的指针,并且通知中心需要指向bar的指针。