I am trying to add images that have been stored to a NSMutableArray. As loop through, I can see each image but when I try to add them to my images array, I get a count of 0.
I have the following code:
.h
#import <UIKit/UIKit.h>
@class Schedule;
@interface PMCViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>
@property (weak, nonatomic) NSMutableArray *images;
@property (weak, nonatomic) IBOutlet UIScrollView *scrollView;
@property (weak, nonatomic) Schedule *schedule;
- (IBAction)OpenAdmin:(id)sender;
- (IBAction)OpenSchedules:(id)sender;
@end
and them in my implementation file:
.m
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES];
NSArray *schedules = [[ScheduleStore sharedStore] allSchedules];
scrollView.delegate = self;
scrollView.scrollEnabled = YES;
scrollView.pagingEnabled = YES;
int scrollWidth = 120;
scrollView.contentSize = CGSizeMake(scrollWidth,80);
int xOffset = 0;
for (int i=0; i < [schedules count]; i++) {
Schedule *selectedSchedule = [schedules objectAtIndex:i];
NSString *ik = [selectedSchedule imageKey];
UIImageView *img = [[UIImageView alloc] init];
//img.bounds = CGRectMake(10, 10, 50, 50);
//img.frame = CGRectMake(5+xOffset, 0, 50, 50);
//img.backgroundColor = [UIColor blackColor];
//img.image = [[ScheduleImageStore sharedStore] imageForKey:ik];
[img setBounds:CGRectMake(10, 10, 50, 50)];
[img setFrame:CGRectMake((5+xOffset), 0, 50, 50)];
[img setBackgroundColor:[UIColor blackColor]];
[img setImage:[[ScheduleImageStore sharedStore] imageForKey:ik]];
[images addObject:img];
scrollView.contentSize = CGSizeMake(scrollWidth+xOffset,50);
[scrollView addSubview:[images objectAtIndex:i]];
xOffset += 70;
}
NSLog(@"Number of img added: %i",[images count]);
[[self scheduleView] reloadData];
}
I tried both dot notation and regular notation but that didn't make a difference. I can't seem to add items to the images array. Could this be a memory issue? Any ideas?
imagesis aweakproperty, how are you assigning it? Where is this mutable array coming from? Did you remember to alloc/init it?