views:

451

answers:

2

I am writing an iPhone application and needed to use the address book functionality. For this to work, it is necessary to specify a ABPeoplePickerNavigationControllerDelegate on the ViewController.

The problem is that I am creating all fields and buttons dynamically runtime, and thus does not have any custom ViewController - using only UIViewController class.

My question is then - how can I specify the delegate runtime without having to create a ViewController class just for this purpose.

A: 

You need to implement the delegate somewhere. Make it its own object or add it to your application controller.

obj yourDelegate obj yourABPeoplePickerNavController

[yourABPeoplePickerNavController setDelegate:yourDelegate]

sylvanaar
Hmmm...I am not completely following you here...Will yourDelegate be the name of the class that implements the functions?If I e.g. implement the delegate functions in a class called myClass, can I use setDelegate:myClass then?
Stein Rune Risa
A: 

I see that I have been a bit unprecise with what I meant. When talking about delegates, I really meant protocols.

E.g. normally one would implement a viewcontroller class that are subclassing UIViewController, and specify the protocol like this:

@interface mySpecialViewController: UIViewController

The problem in my case is that I do not want to create a mySpecialViewController class file, I just want to create one viewcontroller runtime of type UIViewController.

My questions are:

  1. Is the protocol specification optional? If I do not create a class file, I won't have any place to add the -statement - or could I do it somehow runtime? I will still implement all necessary protocol functions.

  2. If I implement the protocol (delegate) functions in the same class as I create the ViewController can I e.g. do like this:

[myClassWithViewController setDelegate:myClassWithViewController]

Stein Rune Risa