说这self
是对象myObject
,我做类似的事情[self setDelegate:theDelegate]
从内部theDelegate
如何访问myObject
?
你不能。委托不需要知道它委托的对象。大多数委托方法都有一个参数,该参数包含一个指向称为委托的实例的指针,以防委托在接收到来自它的消息时需要与委托对象进行交互。这就是你应该做的一切。
UITextField
示例 -完成编辑后更改实例的背景颜色:
- (void)textFieldDidEndEditing:(UITextField *)textField
{
// textField is a pointer to an instance that called us (the delegate)
textField.backgroundColor = [UIColor redColor];
}