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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:54:54+00:00 2026-05-23T13:54:54+00:00

I have an nsarray that when I NSLog it from one of my methods

  • 0

I have an nsarray that when I NSLog it from one of my methods I can see its contents, but when I try to look inside it from elsewhere it seems to be empty. I am aware that my memory management needs some work, could anyone help explain whats happening here?

NEW CODE

WorkOutList.h

#import <UIKit/UIKit.h>


@interface WorkOutList : UIViewController {

    NSManagedObjectContext *managedObjectContext;
    NSMutableArray *customWorkouts;
    NSArray *passedWorkout;
}

@property(nonatomic, retain)NSManagedObjectContext *managedObjectContext;
@property(nonatomic, retain)NSMutableArray *customWorkouts;
@property(nonatomic, retain)NSArray *passedWorkout;

-(IBAction)customWorkouts:(id)sender;

-(void)passWorkoutBack:(NSArray *)workout;


@end

WorkOutList.m

@implementation WorkOutList

@synthesize managedObjectContext, customWorkouts, passedWorkout;

- (void)viewDidLoad {
    [self setupContext];
    NSLog(@"View Did Load");
    customWorkouts = [[NSMutableArray alloc] init];
    passedWorkout = [[NSArray alloc] init];
    [super viewDidLoad];
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self fetchWorkoutList];
    NSLog(@"View will Appear");
    NSLog(@"Array from View Will Appear : %@", passedWorkout);

}

-(IBAction)customWorkouts:(id)sender{
    CoCoachAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
    SelectedWorkout *selectedWorkout = [[SelectedWorkout alloc] initWithStyle:UITableViewStyleGrouped];

    [selectedWorkout recieveNeededData:customWorkouts];

    [appDelegate.practiceNavController pushViewController:selectedWorkout animated:YES];
    [selectedWorkout release];
}

-(void)passWorkoutBack:(NSArray *)workout{
    passedWorkout = workout;
    [passedWorkout retain];
}

- (void)dealloc {
    [super dealloc];
}

SelectedWorkout.h

#import <UIKit/UIKit.h>


@interface SelectedWorkout : UITableViewController {


    NSMutableArray *workoutListForTable;
}

@property(nonatomic,retain)NSMutableArray *workoutListForTable;

-(void)recieveNeededData:(NSMutableArray *)workoutList;

@end

SelectedWorkout.m(aside from all the stuff to set up the tableView)

    @implementation SelectedWorkout

    @synthesize workoutListForTable;

    -(void)recieveNeededData:(NSMutableArray *)workoutList{

        if (workoutListForTable != workoutList) {
            workoutListForTable = workoutList;  
        }

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
        [tableView deselectRowAtIndexPath:indexPath animated:YES];

        CoCoachAppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
        WorkOutList *workoutListView = [[WorkOutList alloc]init];

        [workoutListView passWorkoutBack:[workoutListForTable objectAtIndex:indexPath.row]];
        [appDelegate.practiceNavController popViewControllerAnimated:YES];
    }

    - (void)dealloc {

        [workoutListForTable release];
        [super dealloc];
    }


    NSLog(@"other table : %@", workoutListForTable);
    [workoutListForTable retain];
}
  • 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-23T13:54:55+00:00Added an answer on May 23, 2026 at 1:54 pm

    This is what I think I understand about the flow of your app:

    1. passWorkoutBack gives your view controller an NSArray, which it places in ‘passedWorkout’.
    2. viewDidLoad is called and your ‘passedWorkout’ is reinitialised as an empty array.
    3. viewWillAppear is called and you realise your array is empty.

    To be honest, I think this comes from a lack of understanding of designing robust code (don’t worry, it’s the hardest thing to learn in programming). Here are a few tips that I think would make this app flow smoother:

    1. Create a new init method for your viewController class and, in it, include an argument to give pass this workout array.
    2. If you get an array from somewhere, all you need to do is retain it (either by using a property as Inspire48 said, or by calling retain on the object as you’ve already done), you don’t even need to allocate or initialise the array before you get it from wherever you get it.
    3. Understand the viewController lifecycle. Do you know the difference between viewDidLoad and viewWillAppear? If you don’t, learn, because they are both good tools when utilised properly.

    Anywho, I hope this helped and that I wasn’t too ‘preachy’. I’m assuming a lot about your app and you, so correct me on anything I’m wrong about. Cheers.

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

Sidebar

Related Questions

I have an nsarray that when I NSLog it from one of my methods
How can I save the string that match from one NSArray with one index
I have an NSArray of (Product) objects that are created by parsing an XML
I have code that works great for adding a button to the toolbar: NSArray*
I have a tabbar application that has one screen that displays statistics based on
I have a server-side php-script that fetches results from a MySQL table. I am
this is one of many EXC_BADACCES questions, but I have done research for a
I am trying to create an NSArray from a .plist file, but I keep
I'm trying to create an application, and in that I'm receiving some contents from
I have used the code from apples example from this page: Link , but

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.