我有三个ViewController; A,B和C。
A提出B,B提出C。
如何将数据从C传递回A?
我将B的代表设置为A。
BViewController *bvc = [self.storyboard instantiateViewControllerWithIdentifier:@"B"];
bvc.delegate = self;
我可以将C的代表设置为A吗?
喜欢:
CViewController *cvc = [self.storyboard instantiateViewControllerWithIdentifier:@"C"];
cvc.delegate = (self's parent delegate)
?
还是我需要将C的代表设置为B,然后成为A?
最佳答案
将视图控制器C的委托设置为B; B设置了它的委托人A。B上现在有一个名为sendMessageToA的方法:因此,在C点,它向其委托人发送了“sendMessageToA”,然后B可以将所需的任何数据发送给A。
或者,您可以只将消息从B转发到A。因此C将向其委托人(在这种情况下为B)发送消息。 B说:“我不知道此消息,让我转发。” B将消息发送给A。
该链接很好地解释了这个概念:http://www.mikeash.com/pyblog/friday-qa-2009-03-27-objective-c-message-forwarding.html
关于objective-c - 设置一个代表自己的代表?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10901216/