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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:11:16+00:00 2026-06-04T15:11:16+00:00

this is probably simple but I’m stuck! Basically I have a parent and child

  • 0

this is probably simple but I’m stuck!

Basically I have a parent and child view controller, and I’m trying to pass data from the child to the parent.

//Child VC interface

@protocol ANSearchGetawayFilterDelegate
    -(void)selectedCell:(NSString *)cellTitle;
@end

@interface ANSearchGetawayFilterViewController : UIViewController <UITableViewDelegate,     UITableViewDataSource, UISearchBarDelegate>
{
   NSString* cellTitle;
}
@property (nonatomic, assign) id<ANSearchGetawayFilterDelegate> delegate;

@end

//Child VC implementation

@implementation ANSearchGetawayFilterViewController
@synthesize delegate = _delegate;

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *selectedCell = [tableView cellForRowAtIndexPath:indexPath];
    cellTitle = selectedCell.textLabel.text;
    [[self  delegate] selectedCell:cellTitle];

    [self dismissModalViewControllerAnimated:YES];
}

//Parent VC interface

#import "ANSearchGetawayFilterViewController.h"

@interface ANGetawayFilterViewController : UIViewController <ANSearchGetawayFilterDelegate>
{
    NSString* _cellText;
}

//Parent VC Implementation

   - (id)initWithNibName:(NSString*)nibNameOrNil bundle:(NSBundle*)nibBundleOrNil
    {
        self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
        if (self)
        {
            // Custom initialization
            ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
            search.delegate = self;
        }
        return self;
    }

//delegate method

    -(void)selectedCell:(NSString *)cellTitle
    {
        _cellText = cellTitle;
        NSLog(@"cell text %@", _cellText);
    } 

the delegate method is never called and when is NSLog the _cellText else where it comes up as null…what am I doing wrong? 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-04T15:11:20+00:00Added an answer on June 4, 2026 at 3:11 pm

    You are most likely creating a new instance of ANSearchGetawayFilterViewController when you present it and not configuring the delegate on it.

    When you called

    ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
    search.delegate = self;
    

    you created an instance of ANSearchGetawayFilterViewController and then set the delegate up correctly, but you never stored this instance of ANSearchGetawayFilterViewController anywhere. So later on when you come to present it you call again

    ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
    

    which gives you a completely different instance, which you then need to configure again. For example

    ANSearchGetawayFilterViewController *search = [[ANSearchGetawayFilterViewController alloc] init];
    ANSearchGetawayFilterViewController *search1 = [[ANSearchGetawayFilterViewController alloc] init];
    
    NSLog(@"%d", search1 == search);
    
    #=> 0
    

    To fix update your code to be

    - (BOOL)textFieldShouldBeginEditing:(UITextField*)textField;
    {
        BOOL shouldBeginEditing = YES; 
        NSLog(@"text field should begin editing"); 
    
        ANSearchGetawayFilterViewController *myANSearchGetawayFilterViewController = [[[ANSearchGetawayFilterViewController alloc] init] autorelease]; 
        myANSearchGetawayFilterViewController.delegate = self;    // <--- configure the delegate
    
        [self presentModalViewController:myANSearchGetawayFilterViewController animated:YES];
        [self closeAllPickers]; 
        return shouldBeginEditing; 
    }
    

    I wouldn’t make it an ivar as the likelihood is you will present this viewController momentarily just to select some data and then get rid of it, so it is probably safe to discard it and make a new one each time.

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

Sidebar

Related Questions

I'm new to jQuery so this is probably simple, but... If I have this
Okay, this is probably very simple but, I have the below checks (not at
I know this is probably a simple question but, I have a ASP.NET WebSite
This is probably pretty simple but I'm trying to take the value from an
This is probably a simple answer but I can't find it. I have a
I am new so this is probably simple but I have looked everywhere and
I know this probably really simple but Im not sure what im doing wrong...
This is probably very simple but it's really confusing me. When I implement the
Its been a long day and this is probably extemely simple but how do
This is probably a simple question but I can't seem to figure out how

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.