谁能解释一下someViewController.delegate = self
和self.delegate
的含义吗?他们在哪里帮助我们?
谁能解释一下someViewController.delegate = self
和self.delegate
的含义吗?他们在哪里帮助我们?
给你send messages个.
例如:如果您使用加速计代理,您将收到有关加速计的消息.
如果你使用新的中微子探测代表,你将得到有关在该地区探测到的任何中微子的信息.
如果使用弹出窗口,弹出窗口会向您发送消息.这样做的方式是通过弹出窗口的委托.有很多很多例子.
因此,代表们发送信息.
就这么简单.
100
答案是:它将消息发送到您设置".delegate"的位置.
当你"设置代理"时,你所做的就是说出你希望消息go 哪里.
因此
等等.delegate=amazingPlace将向"amazingPlace"发送消息.
等等.delegate=Somewhere将消息发送到"Somewhere".
等等.delegate=self将发送消息......100
很多时候,你想让信息传给"你",所以你只需要说"blah.delegate=self"
It is a very common mistake, to forget that line of code.
如果你忘记了那行代码,你就吃饱了.这些信息会持续nowhere次,而你却在挠头,试图找出哪里出了问题.
还有一件事你必须做:当你使用委托人时,你必须事先宣布,你想使用委托人.
怎么做?
这很容易...
在过go ,客观公正...
// old days!
@interface AppDelegate_Pad : NSObject <UIApplicationDelegate>
@interface BigTop : UIViewController <ASIHTTPRequestDelegate,
UIPopoverControllerDelegate>
@interface Flying : UIViewController <UIAccelerometerDelegate>
您可以看到,"BigTop"想要使用两个委托,即ASIHTTPRequestDelegate和UIPopoverControllerDelegate.而"飞行"只想使用一个代理——它想使用加速计.
在Swift ...
class YourClass:UIViewController, SomeDelegate, AnotherDelegate
如果不到处使用代理,你就无法在iPhone上做很多事情.
在iOS中,代理在任何地方、任何时候都被使用.
一个类可能会使用十几个委托,这是完全正常的.也就是说,你的班级想要从十几位代表那里得到信息.
现在有了Swift ,你只需打字
blah.delegate = self
这就是全部.
这就是你要做的.代表send messages.你必须说你想让这些信息消失.非常典型的情况是,你希望他们go "你",所以在这种情况下,你只需说blah.delegate=self
.