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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:47:02+00:00 2026-05-22T18:47:02+00:00

I have two UITableViewControllers and need to pass the value from the child view

  • 0

I have two UITableViewControllers and need to pass the value from the child view controller to the parent using a delegate. I know what delegates are and just wanted to see a simple to follow example.

Thank You

  • 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-22T18:47:03+00:00Added an answer on May 22, 2026 at 6:47 pm

    Here’s a simple example:

    Let’s say the child view controller has a UISlider and we want to pass the value of the slider back to the parent via a delegate.

    In the child view controller’s header file, declare the delegate type and its methods:

    ChildViewController.h

    #import <UIKit/UIKit.h>
    
    // 1. Forward declaration of ChildViewControllerDelegate - this just declares
    // that a ChildViewControllerDelegate type exists so that we can use it
    // later.
    @protocol ChildViewControllerDelegate;
    
    // 2. Declaration of the view controller class, as usual
    @interface ChildViewController : UIViewController
    
    // Delegate properties should always be weak references
    // See http://stackoverflow.com/a/4796131/263871 for the rationale
    // (Tip: If you're not using ARC, use `assign` instead of `weak`)
    @property (nonatomic, weak) id<ChildViewControllerDelegate> delegate;
    
    // A simple IBAction method that I'll associate with a close button in
    // the UI. We'll call the delegate's childViewController:didChooseValue: 
    // method inside this handler.
    - (IBAction)handleCloseButton:(id)sender;
    
    @end
    
    // 3. Definition of the delegate's interface
    @protocol ChildViewControllerDelegate <NSObject>
    
    - (void)childViewController:(ChildViewController*)viewController 
                 didChooseValue:(CGFloat)value;
    
    @end
    

    In the child view controller’s implementation, call the delegate methods as required.

    ChildViewController.m

    #import "ChildViewController.h"
    
    @implementation ChildViewController
    
    - (void)handleCloseButton:(id)sender {
        // Xcode will complain if we access a weak property more than 
        // once here, since it could in theory be nilled between accesses
        // leading to unpredictable results. So we'll start by taking
        // a local, strong reference to the delegate.
        id<ChildViewControllerDelegate> strongDelegate = self.delegate;
    
        // Our delegate method is optional, so we should 
        // check that the delegate implements it
        if ([strongDelegate respondsToSelector:@selector(childViewController:didChooseValue:)]) {
            [strongDelegate childViewController:self didChooseValue:self.slider.value];
        }
    }
    
    @end
    

    In the parent view controller’s header file, declare that it implements the ChildViewControllerDelegate protocol.

    RootViewController.h

    #import <UIKit/UIKit.h>
    #import "ChildViewController.h"
    
    @interface RootViewController : UITableViewController <ChildViewControllerDelegate>
    
    @end
    

    In the parent view controller’s implementation, implement the delegate methods appropriately.

    RootViewController.m

    #import "RootViewController.h"
    
    @implementation RootViewController
    
    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        ChildViewController *detailViewController = [[ChildViewController alloc] init];
        // Assign self as the delegate for the child view controller
        detailViewController.delegate = self;
        [self.navigationController pushViewController:detailViewController animated:YES];
    }
    
    // Implement the delegate methods for ChildViewControllerDelegate
    - (void)childViewController:(ChildViewController *)viewController didChooseValue:(CGFloat)value {
    
        // Do something with value...
    
        // ...then dismiss the child view controller
        [self.navigationController popViewControllerAnimated:YES];
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two identical tables and need to copy rows from table to another.
I have two View Controllers: TableViewController (which is used as a modal view controller)
Have two variables both containing integers: var input; var value; Need to perform arithmetic
I have two applications written in Java that communicate with each other using XML
I have a NSFetchedResultsController which is fetching objects from a NSManagedObjectContext . I'm using
I have a UINavigationController with two UITableViewControllers pushed onto its stack. Is there any
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have
I have two lists: List<string> _list1; List<string> _list2; I need add all _list2 different
I have a UINavigationController with two UITableViewControllers (A and B). A is displayed first
I have two UITableViewControllers with a fairly simple ui flow. One UITableViewController loads another

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.