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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T14:36:03+00:00 2026-06-06T14:36:03+00:00

I’ve read up on couple of questions here on SO about passing data between

  • 0

I’ve read up on couple of questions here on SO about passing data between two View Controllers and seen different ways suggested of doing it. My problem is as follows:

I have a view controller (lets call it a “A”) that has a searchbar in a toolbar. Nothing else. Then I have another view controller (“B”) that is responsible for displaying a popover view when the user presses the search button on the keyboard when searching in the searchbar.
This all works. The user enters text, presses the search button, the popover is shown. Great.

Now I have yet to display any search results in the popover tableview and am trying to pass a NSMutableArray to a function in B as an argument:

in B.h:

@property (nonatomic, retain) NSMutableArray *searchResults;

in B.m:

    @synthesize searchResults;

     -(void)setSearchResults:(NSMutableArray *)resultArray{
         [self.searchResults removeAllObjects];
         [self.searchResults addObjectsFromArray:resultArray];
     }

in A.h:

#import "B.h"
@property(nonatomic, retain) B *viewControllerObjectB;

in A.m:

@synthesize viewControllerObjectB;

 //The searchResultsArray is passed on from another function
-(void)communicateWithB:(NSMutableArray *)searchResultsArray{

    //I initialize the viewControllerObjectB in here

    NSMutableArray *temp = [[NSMutableArray alloc] initWithArray:searchResultsArray];
    [viewControllerObjectB setSearchResults:temp];
}

Now this all works except I do not get the content of temp passed on into the function in B.m. I’ts empty (nil). This is my problem.

I’m fairly new to iOS so all help would be appreciated.

EDIT: Forgot to mention that I’m using ARC.

  • 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-06T14:36:05+00:00Added an answer on June 6, 2026 at 2:36 pm

    You didn’t initialize your array (that’s why it’s nil). So in alloc method you should:

    - (id)init {
        self = [super init];
    
         if (self) {
              self.searchResults = [NSMutableArray arrayWithCapacity:10];
         }
    }
    

    I also spotted 2 problems in your code:

    @synthesize searchResults;
    
         -(void)setSearchResults:(NSMutableArray *)resultArray{
             //PROPERTY LOGIC IS RETAIN, SO YOU NEED TO RELEASE/RETAIN WHEN YOU OVERRIDE A SETTER
             if (searchResults != resultArray) {
                  [searchResults release];
                  searchResults = [resultArray retain];
             }
         }
    
    
    -(void)communicateWithB:(NSMutableArray *)searchResultsArray{
    
        //I initialize the viewControllerObjectB in here
        //MEM. LEAK ON TEMP
        NSMutableArray *temp = [[[NSMutableArray alloc] initWithArray:searchResultsArray] autorelease];
        [viewControllerObjectB setSearchResults:temp];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a view passing on information from a database: def serve_article(request, id): served_article
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I want to construct a data frame in an Rcpp function, but when I
I am using parse_ini_file to read the contents of a file however it is
I'm having trouble keeping the paragraph square between the quote marks. In firefox the

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.