Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4321324
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T08:43:57+00:00 2026-05-21T08:43:57+00:00

I was going through some code examples and came across this application which which

  • 0

I was going through some code examples and came across this application which which has the following classes

1) FaceView Class – Draws a face and a customizable smile
2) HappinessViewContoller Class – sets the smile in the face drawn based on input of a slider in the interface.

The program actually implements a delegate protocol in the FaceView.h class as seen below

#import <UIKit/UIKit.h>

@class FaceView;

@protocol FaceViewDelegate
- (float)smileForFaceView:(FaceView *)requestor;  // -1.0 (frown) to 1.0 (smile)
@end

@interface FaceView : UIView {
    id <FaceViewDelegate> delegate;
}

@property (assign) id <FaceViewDelegate> delegate;

@end

and the HappinessViewController declares that it is using the FaceViewDelegate

#import <UIKit/UIKit.h>
#import "FaceView.h"

@interface HappinessViewController : UIViewController <FaceViewDelegate>
{
    int happiness; // 0 to 100
    UISlider *slider;
    FaceView *faceView;
}

@property int happiness;

@property (retain) IBOutlet UISlider *slider;
@property (retain) IBOutlet FaceView *faceView;

- (IBAction)happinessChanged:(UISlider *)sender;

@end

I am a little confused on why a delegate protocol is required in this scenario. Can I just set the method “- (float)smileForFaceView:(FaceView *)requestor;” directly in the HappinessViewController without declaring a delegate to the faceView?

Thanks!

Zhen Hoe

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T08:43:57+00:00Added an answer on May 21, 2026 at 8:43 am

    It is never required to create a protocol for delegates, but it makes it easier to ensure compatibility if there are methods which the delegate is required to implement. In this case, when the delegate is set, the FaceView object could use [newDelegate conformsToProtocol:@protocol(FaceViewDelegate)] to make sure the delegate implements any required methods. If they decide to add more required methods, they won’t have to change their code because the delegate has to implement all required methods to conform.

    If you don’t have any required methods, then this isn’t as beneficial since you can’t use it for type checking. If you are writing library code, however, you should still use it, because you can put all of your possible delegate methods in there and use it as a reference.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was going through some code and came across a scenario where my combobox
I was just going through some codes of C++. Where in I came across
I'm going through some old stored procedures at work and constantly come across CASE
Please help me with this code - I am basically going through a book
I was looking through the source of OpenDE and I came across some wierd
I was recently going through some code and considering whether I need to be
I'm using VS2010 and I'm going through some examples in my book and I'm
While going through university and from following the development of SO, I've heard a
So I am going through our database and removing some unneeded access levels that
I'm getting this error in Python3.2 on a simple print statement. I'm going through

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.