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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:23:37+00:00 2026-05-27T21:23:37+00:00

I am trying to implement a delegate to enable a modal view to pass

  • 0

I am trying to implement a delegate to enable a modal view to pass data back to a UIViewController.

I have two view controllers, my main UIViewController and the modal. Using the code below, the [delegate translationTextEntered:@”Test”]; doesn’t affect the main screen (i.e. ‘translationTextEntered’ never gets called)

My Main Controller

This contains a method to be called when the modal has the user’s value:

MainViewController.h

- (void)translationTextEntered:(NSString *)txt;

MainViewController.m

- (void)translationTextEntered:(NSString *)text
{
    [self dismissModalViewControllerAnimated:YES];
    _text.text = [NSString stringWithFormat:@"%@" , text];
}

My Modal Controller

This contains a UITableView which contains the delegate and, when an item is selected, should trigger the delegate callback.

SuggestionViewController.h

@protocol SelectTranslationDelegate <NSObject>
- (void)translationTextEntered:(NSString *)text;
@end

@interface SuggestionViewController : UIViewController <UITableViewDataSource, UITableViewDelegate, SelectTranslationDelegate>
{
    id<SelectTranslationDelegate> delegate;
}

@property (nonatomic, weak)id delegate;

SuggestionViewController.h

@synthesize delegate = _delegate;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
     ...      
    [delegate translationTextEntered:@"f"];

}
  • 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-27T21:23:37+00:00Added an answer on May 27, 2026 at 9:23 pm

    It should be something like this:

    MainViewController.h

    #import "SuggestionViewController.h"
    
    @interface MainViewController : UIViewController <SelectTranslationDelegate>
    
    // - (void)translationTextEntered:(NSString *)txt;  <- Not required
    

    The declaration of - (void)translationTextEntered:(NSString *)txt; is not required because you say that you conform to the SelectTranslationDelegate protocol (The bit between the </>)

    MainViewController.m

    // The method where you instantiate SuggestionViewController
    {
         // .. do your work
    
         SuggestionViewController *suggestionViewController = [[SuggestionViewController alloc] init];
    
         suggestionViewController.delegate = self; // <- This is the missing line
    
         [self presentModalViewController:suggestionViewController animated:YES];
         // [suggestionViewController release]; suggestionViewController = nil; // I'm assuming your using ARC
    
    }
    

    It should also be noted that your Modal view controller should not conform to SelectTranslationDelegate as this is most likely not your intention. So you declaration should be like:

    @interface SuggestionViewController : UIViewController <UITableViewDataSource, UITableViewDelegate>
    

    It is MainViewController that you want to respond to translationTextEntered: not SuggestionViewController. The SuggestionViewController is that one that makes the message call of translationTextEntered: on the delegate

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

Sidebar

Related Questions

I'm currently trying to implement a UITableView with a delegate and data source that
I'm trying to make my Core data backed UITableView have reorder ability, After implement
I'm trying to have a Terms of Service modal view display when my application
trying to implement a dialog-box style behaviour using a separate div section with all
I am trying to implement the delegate Pattern in Objective-C, however I am experiencing
I am trying to implement a decorator chain for my data-access based on IRepository.
Trying to implement AVAudioplayer and get some metering data of the played music, but
I am trying to implement a delegate method for my Cocoa document-based application which
I'm trying to implement zooming functionality using a UIScrollView in MonoTouch but I just
I am trying to implement a popover view in a tableview controller. My intention

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.