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

  • Home
  • SEARCH
  • 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 8714103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T05:30:32+00:00 2026-06-13T05:30:32+00:00

I am a newbie to iPhone development and have some basic questions to ask

  • 0

I am a newbie to iPhone development and have some basic questions to ask about protocols and delegates. I have two view controllers: view controller and viewcontroller2nd. I have UITextField in one of them and would like to type something (like a name) in it and in the viewcontroller2nd, I have a UILabel and i would like it to appear Hello, name when the UITextField is changed.

I am following this video: http://www.youtube.com/watch?v=odk-rr_mzUo to get the basic delegate to work in a single view controller.

I am using protocols to implement this:

SampleDelegate.h

#import <Foundation/Foundation.h>

@protocol ProcessDelegate <UITextFieldDelegate>
@optional
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
@end

@interface SampleDelegate : NSObject
{
    id <ProcessDelegate> delegate;
}

@property (retain) id delegate;

@end

SampleDelegate.m

#import "SampleDelegate.h"

@implementation SampleDelegate

@synthesize delegate;

- (BOOL)textFieldShouldReturn:(UITextField *)textField{

    lbl.text = [NSString stringWithFormat:@"Hello, %@",txtField.text];
    [txtField resignFirstResponder];

}

@end

ViewController.h

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

@interface ViewController : UIViewController <ProcessDelegate>
{
    IBOutlet UITextField *txtField;
}

@end

Viewcontroller.m

#import "ViewController.h"


@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

ViewController2nd.h

#import <UIKit/UIKit.h>

@interface ViewController2nd : UIViewController <ProcessDelegate> {

    IBOutlet UILabel *lbl;
}



@end

and ViewController2nd.m is standard code from Xcode.

My question is how do i link my delegate function to my viewcontroller and viewcontroller2nd to get it working?

Pardon me if the question is stupid.. Need some guidance. Do point me any other mistakes that i am doing as well.. Thanks..

  • 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-06-13T05:30:34+00:00Added an answer on June 13, 2026 at 5:30 am

    Your delegation is a bit… Off.

    Firstly: Don’t override UIKit delegate methods through protocol inheritance. It’s pointless. Why not just make your class conform to the specified delegate in the first place?

    @protocol ProcessDelegate //No more protocol inheritance!
     //...
    @end
    

    Secondly: When an object has defined a protocol, a valid instance of that object must be in use by its delegate (or at least passed to it). So, anything that wants to be the delegate of SampleDelegate (really a bad name for a class, by the way) would initialize a valid SampleDelegate object, and call -setDelegate: as though it were any other property.

    //#import "SampleDelegate"
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
        //make this a property, so it isn't crushed when the function exits.
        SampleDelegate *myDelegateObject = [[SampleDelegate alloc]init];
        [myDelegateObject setDelegate:self];  //conform to the delegate
    }
    

    Thirdly: You don’t actually define any delegate methods! What’s the point of delegation if there’s nothing to delegate!l

    @protocol ProcessDelegate 
     -(void)someMethod;
    @end
    

    Fourth, and most important: Never, ever, ever, ever use the retain, or strong storage specifiers with a delegate! Delegate objects are supposed to be weak or assign to prevent nasty retain cycles.

    @property (assign, nomatomic) id delegate;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am a newbie in iPhone development, doing my first app. I have some
I'm a relative newbie on iPhone app development but have successfully created a tab
I am a newbie on iPhone development. I have declared a variable on my
I'm a newbie doing Objective-C, coming from Flex/Actionscript development. I have an iPhone app
Just a newbie with iPhone development.. I just have a small problem but huge
Since I am a newbie in iPhone development, I need some advice on how
hello all m a newbie to iphone development. I have 5 themes in my
I am total newbie to Android but I have some knowlege of iPhone apps.
Hii Friends, i m newbie to iphone development , i have to design a
I am a newbie for iphone development, i wish to show some list of

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.