开发者

iphone/objective c (simple) question

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.peo开发者_如何转开发plePickerDelegate presentModalViewController:picker2 animated:YES];

Regards


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.)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜