C
C
casualfatboy2015-04-05 18:44:02
Objective-C
casualfatboy, 2015-04-05 18:44:02

Objective C - what does delegate: self mean?

A UIActionSheet object is created, in the parameters of which delegate is specified: self
What exactly does this mean? Where exactly is the message sent in this case?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Roman, 2015-04-06
@casualfatboy

I read both answers, and if I had not been familiar with this, I would not have understood anything.
Most likely you are displaying a UIActionSheet in some UIViewController. By setting delegate:self (and in some classes this is set not in the constructor, but manually), you say that you will implement some of your behavior on interaction with this object.
When you set an object as a delegate, this object most often must implement at least one of the delegate methods that are specified in the protocols, for UIActionSheet it is UIActionSheetDelegate.
Those. your UIViewController will be described like this
@ interface MyController : UIViewController < UIActionSheetDelegate >
In order not to get into the documentation, all protocol methods for convenience begin with actionSheet. All you need to do is start typing the beginning of the function "- actionSh…" then you will be shown all the methods that start like this and there will be a brief description of them.
Delegation is very important and often encountered in development, so I advise you to read about them at Apple
https://developer.apple.com/library/ios/documentat...

F
feniksqip, 2015-04-05
@feniksqip

Which "takes over task X" (i.e., we specify our UIView). Our view is responsible for what is happening!

I
iMike, 2015-04-05
@iFamily

self is the current class, for example it could be the current UIVIewController.
Accordingly, when you say that the delegate for UIActionSheet is self, this means that in the current class you need to "register" / add methods from UIActionSheetDelegate and they will work.
In general, use UIAlertController already, otherwise UIActionSheet is outdated.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question