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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:01:43+00:00 2026-06-17T23:01:43+00:00

I am a newbie in xcode. I am trying to pass an array from

  • 0

I am a newbie in xcode. I am trying to pass an array from one view to another. I want to pass an integer profileid in the ProfileViewController to an array in the FavouritesViewController.
Once the FavouritesViewController is loaded the log will display the array.

Here’s my code:

ProfileViewController.h

- (IBAction)AddFavouritesClicked:(id)sender;

ProfileViewController.m

@synthesize profileid;


int profileid = 0;

- (IBAction)AddFavouritesClicked:(id)sender {

    FavouritesViewController *favController = [[FavouritesViewController alloc]init];
    [favController.favouritesArray initWithObjects:[NSNumber numberWithInt:profileid], nil];
    NSLog(@"%@", favController.favouritesArray);


}

FavouritesViewController.h

@interface FavouritesViewController : UITableViewController
{
    NSMutableArray *favouritesArray;
}

@property(nonatomic, retain)NSArray *favouritesArray;
@end

FavouritesViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    NSLog(@"%@", favouritesArray);
}

So far the favouritesArray value is always null

Any help would be very much appreciated. Thanks in advance!

Here is my Log every time I clicked the Addtofavoutites button

2013-01-27 22:54:52.865 Ad&Promo[8058:c07] (
2
)
2013-01-27 22:56:10.958 Ad&Promo[8058:c07] (
2
)
2013-01-27 22:56:11.705 Ad&Promo[8058:c07] (
2
)
2013-01-27 22:56:12.191 Ad&Promo[8058:c07] (
2
)

But instead I want it to look like this..

2013-01-27 22:54:52.865 Ad&Promo[8058:c07] (
2,2,2,2
)
  • 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-17T23:01:45+00:00Added an answer on June 17, 2026 at 11:01 pm

    First of all, you should review the syntax for your array creation. It should be:

    favController.favouritesArray = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:profileid], nil];
    

    This alone will not fix your issues, though, I gues

    This is quite a typical error that shows up here on S.O. In the following 2 statements:

    FavouritesViewController *favController = [[FavouritesViewController alloc]init];
    favController.favouritesArray = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:profileid], nil];
    

    you are allocating a new FavouritesViewController. That has nothing to do with any other FavouritesViewController that you have already initialized in your app. That explain why its internal array is empty.

    What you need to do is make your ProfileViewController instance aware of your FavouritesViewController instance (as opposed to instantiating a private instance of the latter inside the former).

    So, simply define a FavouritesViewController property inside of ProfileViewController, and initialize it properly. Then you will be able to do:

    - (IBAction)AddFavouritesClicked:(id)sender {
    
        self.favController.favouritesArray = [[NSArray alloc] initWithObjects:[NSNumber numberWithInt:profileid], nil];
    

    }

    and this will set the value you need to set into the other view controller you have.

    EDIT:

    a better design for this kind of requirement is using a model (as in model-view-controller).

    Instead of letting one of the two controllers know about the other, you create a new class (the model) responsible for holding all the shared data in your app.

    This class would be accessible from any other class in your app, so that they could set and get the data it stores.

    This class could be a singleton:

    [MyModel sharedModel].favArray = ...
    

    or it could be a class exposing only class methods, e.g.:

    [MyModel setFavArray:...];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

preemptive sorry for the newbie question. I'm trying to load strings from a resource
I'm a newbie to xcode. I'm using xcode 4.3 with lion. I want to
i'm newbie in Xcode programming :) I want to create a karaoke software running
I am a newbie in xcode development. I am trying to implement a web
I'm trying to create a custom generic Xcode behaviour, that once invoked will launch
I'm an Xcode newbie, and I'm trying to make my first training app. Since
I'm nearly a newbie to Xcode 4. There's a way to add to a
newbie for clearcase. Since clearcase's config is rather different from other concept in git,
I'm a newbie in XCode programming. I have following code: CGSize firstSize = CGSizeMake(1.0,1.0);
I'm a complete newbie to Objective-C/XCode and it's been a bit daunting so far.

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.