-2

Possible Duplicate:
How does a delegate work in Objective-C?
Can Someone Help Me To Understand What Is This "Delegate"?

What is Use of Delegate method in Objective-C if I do same functionality using subclass method why we use delegate method in Objective-C

Cœur
  • 37,241
  • 25
  • 195
  • 267
nuttekar
  • 25
  • 6

2 Answers2

0

You may want to implement more delegates, while obj-c supports only single inheritance.

Anyway, always choose composition and interface/delegates over inheritance.

moonwave99
  • 21,957
  • 3
  • 43
  • 64
0

Think of a delegate method as a method external to the class. Any class can then become useful (become the delegate of) the class by complying with the delegate protocol and implementing the required delegate method(s). Delegation adds flexibility without the restrictions inherent to the parent class being carried over by subclassing.

Michael Mangold
  • 1,741
  • 3
  • 18
  • 32
  • in which situation delegate is mostly used in objective c – nuttekar Sep 22 '12 at 12:01
  • Every app is a delegate of the Objective-C runtime, for instance. You see this in the application delegate class' implementation's .h file specifying the UIApplicationDelegate protocol. Other examples would be viewWillLoad/ShouldLoad/DidLoad which are delegate methods of the UIView class. – Michael Mangold Sep 22 '12 at 12:05