views:

50

answers:

2

hi guys

I'm trying to avoid the redeclaration of self, in the following

picker2.peoplePickerDelegate = self;
// showing the picker
[self presentModalViewController:picker2 animated:YES];

Why am i not able to just go like:

[picker2.peoplePickerDelegate presentModalViewController:picker2 animated:YES];

Regards

A: 

Because picker2.peoplePickerDelegate may not be self before your assignment.

(Also, picker2.peoplePickerDelegate is not a UIViewController so sending the -presentModalViewController:animated: message to it is wrong.)

KennyTM
hmm, i think i confused myself doing that, I thought self was being redeclared, where its not. it was to help answer my bigger question at http://stackoverflow.com/questions/2150874/iphone-sdk-bringing-up-viewcontroller-in-shouldcontinueafterselectingperson.I am having trouble bringing up a view controller after being in contact list, and i think it has something to do with self. Can you look at that?
norskben
A: 

Hey you should think of one thing also.

[self presentModalViewController:picker2 animated:YES];

It will work because presentmodalviewcontroller is a method of UIViewController class and

in the method [picker2.peoplePickerDelegate presentModalViewController:picker2 animated:YES];

you are trying to call it with a (id) type i.e. it will be inheritting from a NSObject.

Hope this helps.

Thanks,

Madhup

Madhup