PDA

View Full Version : problem with Delegates..




bytezone
May 5, 2009, 08:27 AM
I am using the Exploring Iphone SDK by Dave and Jeff.

So far I am able to pick up everythin. But yesturday I came across a chapter which uses delegates like this...

interface Control_FunViewController : UIViewController <UIActionSheetDelegate> {
IBOutlet UITextField *nameField;
IBOutlet UITextField *numberField;
IBOutlet UILabel *sliderLabel;
IBOutlet UISwitch *leftSwitch;
IBOutlet UISwitch *rightSwitch;
IBOutlet UIView *switchView;
IBOutlet UIButton *doSomethingButton;


}

Where can read to know more about why <UIActionSheetDelegate> is used. I mean I want to learn more about delegates in cocoa touch frame work. Any good link for this...??

Thanks



robbieduncan
May 5, 2009, 08:35 AM
You are confusing two distinct and very different concepts: delegates and protocols. The <UIActionSheetDelegate> says that this class implements the UIActionSheetDelegate protocol.

PhoneyDeveloper
May 5, 2009, 08:36 AM
Delegates and delegations is an important and ubiquitous concept in Cocoa. Look here for some discussion:

Cocoa Fundamentals Guide/Communication With Objects/Delegates and Data Sources.

You should read the whole guide.

I found this as follows: Open the Documentation window in Xcode. Type in 'delegation' to the search bar at the top of the window. Select Apple iPhone OS 2.2 Doc Set. Choose Full-Text search. A lot of choices appear but this is the best one.

BlackWolf
May 5, 2009, 09:05 AM
You are confusing two distinct and very different concepts: delegates and protocols. The <UIActionSheetDelegate> says that this class implements the UIActionSheetDelegate protocol.

yep, that's something completly different. if you want to know about protocols, that is pretty easy. it's just a way to make sure a class implements some methods. in your example, the protocol does not have any necessary methods, but some optional ones like

actionSheet:clickedButtonAtIndex:

to see everything a protocol defines see the reference for that protocol, like
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIModalViewDelegate_Protocol/UIActionSheetDelegate/UIActionSheetDelegate.html

bytezone
May 5, 2009, 10:57 AM
Sorry for the confusion..it should have been protocols.

I read this
http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/ObjectiveC/Articles/ocProtocols.html#//apple_ref/doc/uid/TP30001163-CH15-BAJJABHJ

It was very usefull. Thanks everyone for valuable suggestions.


yep, that's something completly different. if you want to know about protocols, that is pretty easy. it's just a way to make sure a class implements some methods. in your example, the protocol does not have any necessary methods, but some optional ones like

actionSheet:clickedButtonAtIndex:

to see everything a protocol defines see the reference for that protocol, like
http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIModalViewDelegate_Protocol/UIActionSheetDelegate/UIActionSheetDelegate.html