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 7673103
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T16:26:05+00:00 2026-05-31T16:26:05+00:00

I am passing a string through a delegate and protocol. The string is received

  • 0

I am passing a string through a delegate and protocol. The string is received to the class correctly, but this occurs after the viewDidLoad method is called. The viewDidLoad method needs that string that is passed.

Any ideas on what I can do to get the delegate method to be called before viewDidLoad? I thought this was the idea of the delegate/protocol data passing.

Method where new view is created and pushed:

ViewControllerTwo *two = [[ViewControllerTwo alloc] initWithNibName:@"ViewControllerTwo" bundle:nil];
two.delegate = self;
[two setString:theString];
[self.navigationController pushViewController:two animated:YES];
[two release]; 

In ViewControllerTwo:

- (void)setString:(NSString *)str
{
    self.myString = str;
}

Edit: Thanks for the input. However, I do understand how to pass this data through the init method. I have been testing protocols and delegates lately, and I wanted to see if there was a way to do this. I have successfully passed data like this in another class and it worked. The protocol method was called first setting the string. It seemed like a much cleaner way to handle passing data.

  • 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-31T16:26:07+00:00Added an answer on May 31, 2026 at 4:26 pm

    I think you might be a little confused about what Delegation is used for and why.

    For example you might want to make a protocol in a UIViewController subclass if you were doing some kind of action in that ViewController and needed to inform another subclass that that action is being taken, or of the result of that action.

    Now in order for the subclass that wants to know about the action(the receiver), it has to conform to that protocol in it’s header file.

    You also must “set” the delegate to the receiving class/controller.

    There are many ways to get a reference to the receiving controller/class to set it as the delegate but a common mistake is allocating and initializing a new instance of that class to set it as the delegate, when that class has already been created.What that does is set your newly created class as the delegate instead of the class that’s already been created and waiting for a message.

    What your trying to do is just pass a value to a Newly created class. Since your just creating this UIViewController class all that needed for that is a Property in the receiver(ViewControllerTwo).

    In your case a NSString:

     @Property (nonatiomic, retain) NSString *string; //goes in ViewControllerTwo.h
    

    and of course don’t forget in the main:

      @synthesize string; //Goes in ViewControllerTwo.m
    

    Now there is no need for a setter in your ViewControllerTwo.

     - (void)setString:(NSString *)str  //This Method can be erased
        {                                  //The setter is created for free
            self.myString = str;          // when you synthesized the property
        }   
    

    The setter and Getters are free when you use the @synthesize. Just Pass the value over to the ViewController. The implementation is identical to your code except for the delegate:

      ViewControllerTwo *two = [[ViewControllerTwo alloc] initWithNibName:@"ViewControllerTwo" bundle:nil];
        [two setString:theString];
        [self.navigationController pushViewController:two animated:YES];
        [two release];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Like is available via passing a string through ESQL... but not as an actual
Hi I have a class which includes an array, I'm not passing this through
I've got a std::map: std::map<std::string, std::string> I'm passing string literal to find method. Obviously,
I'm passing query string parameter to .aspx page with 'Ñ' character in value. But
Hi I'm passing path string to Groovy Script from Scala like below but when
I'm used to passing around string like this in my C++ applications: void foo(const
I'm having a bit of trouble passing this parameter to a class i have.
I am trying to intercept a method through a proxy class and am getting
Is there a standard way of passing an array through a query string? To
I am passing a string through a URL to another page whenever a link

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.