Answer the question
In order to leave comments, you need to log in
What are selectors and delegates in Objective-C?
I'm learning objective c. Reached the chapter "Callback" (a book by Aaron Hillegas, translated into Russian).
There are three callback models (Action Receiver, Helper Objects, and Alert Center).
Explain in detail event programming in objective c.
I already **** Xia to re-read the same chapter in the tutorial. On the Internet, I found only incoherent pieces of code, etc.
Answer the question
In order to leave comments, you need to log in
You are reading some complicated and unnecessary book, open the office. documentation and study by examples.
In simple words:
A selector is a method that will process some action
For example: we have a button and we specify a selector with the myButtonWasPressed method, this method will be called when the button is pressed.
[myButton addTarget:self
action:@selector(myButtonWasPressed)
forControlEvents:UIControlEventTouchUpInside];
- (void)myButtonWasPressed {
// Do something about it
}
Delegates - https://vk.com/videos-58860049?section=search&z=vi...
Selectors - https://vk.com/videos-58860049?section=search&z=vi...
ps: don't be afraid, Russian language
try to watch the video on hexlet.org, there are definitely about delegates there.
Read more about the Delegate pattern.
In Objective-C, it is based on the
delegate protocol that implements methods that the executor object cannot implement itself.
For example, let's take a UITableView and its Delegate, which must implement the required methods.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
[myButton addTarget:self
action:@selector(myButtonWasPressed:)
forControlEvents:UIControlEventTouchUpInside];
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question