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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:47:50+00:00 2026-05-23T13:47:50+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 (inside WorkOutList.m) I can see its contents, but when I try to look inside it from a different method inside WorkOutList.m it seems to be empty. I am aware that my memory management needs some work, could anyone help explain whats happening here?

I am using popViewControllerAnimated:YES to return the view from a tableView back to a view controller, but just before I do that I set my array in a method inside WorkOutList. When I NSLog that array from that same method I am returned results, however when i NSLog it from else where it is returned empty.

I have been told that it might be the viewDidLoad method where the array is init, but that the other array in that method customWorkouts still retains its data. So i dunno, any explanation would be really helpful. I want this to work, but I also really want to understand it so I can get on with coding correctly.

Thanks so much!

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:47:50+00:00Added an answer on May 23, 2026 at 1:47 pm

    It looks to me that although you are initializing your array with or so I assume, since on the other line you are only allocating an empty array.

    [self fetchWorkoutList]
    

    You are resetting it here every time:

    [workoutListView passWorkoutBack:[workoutListForTable objectAtIndex:indexPath.row]];
    

    As a note here:

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

    You have the property passedWorkout as retain already, however you need to call it on self

    -(void)passWorkoutBack:(NSArray *)workout{
        self.passedWorkout = workout;
    }
    
    • 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 NSArray and I want to remove duplicates from it. I know that
for an iOS 5.0 application using ARC, i have an NSArray of objects that
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*
Here is the code that I have for my cell of my UITableView: forKeys:[NSArray
I have a NSMutableArray and a NSArray . Both consist of elements that are
I have a tabbar application that has one screen that displays statistics based on
I have built one 'deep' NSMutableDictionary that contains parsed XML data along with other

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.