Hello everybody, I'm new in the Mac programming world and I'm trying to learn to build some iPhone apps. I'm following the Stanford Course and I'm stuck at assignment 4, part 1. I have this code:
PhotoListViewControls, inits PhotoList view with some data. Everything seems to works fine until I call drawRect method. I mean, if I write down:
I receive the right values, but when it comes the time to draw my labels and my images, seems that my IVars are all null
.
Where am I doing wrong?
Thank you very much.
PS: Please
I don't want the solution of the assignment!
PPS: My english is not the best, please feel free to ask me to repeat.
Code:
// PhotoListViewController.m
...
// This is PLVC initWithNibName method
if ( [caller isEqual:@"Josh"] ) {
NSMutableArray *images = [[NSMutableArray alloc] init];
NSMutableArray *titles = [[NSMutableArray alloc] init];
[images addObject:@"photo1.jpg"];
[titles addObject:@"Urban Disaster"];
[images addObject:@"photo2.jpg"];
[titles addObject:@"Concrete Pit"];
photoList = [[PhotoList alloc] initWithData:images andTitles:titles andAuthor:caller];
}
[photoList setNeedsDisplay];
return self;
...
// PhotoList.h
@interface PhotoList : UIView {
...
NSMutableArray *imagesArray;
...
}
...
- (id)initWithData:(NSMutableArray *)images andTitles:(NSMutableArray *)titles andAuthor:(NSString *)author;
...
@end
// PhotoList.m
- (id)initWithData:(NSMutableArray *)images andTitles:(NSMutableArray *)titles andAuthor:(NSString *)author{
if ( self = [super init] ) {
// Arrays do have correct values.
imagesArray = [[NSMutableArray alloc] initWithArray:images];
titlesArray = [[NSMutableArray alloc] initWithArray:titles];
authorIVar = [[NSString alloc] initWithString:author];
}
return self;
}
- (void)drawRect:(CGRect)rect{
...
NSLog(@"%@",imagesArray); // Arrays have null values
for( NSString *images in imagesArray){
CGRect frame = CGRectMake(x, y, 30, 50);
labels = [[UILabel alloc] initWithFrame:frame];
}
return;
}
Code:
// Into PhotoList.m
- (void)aMethodToPrintArrays{
NSLog(titlesArray);
}
// Into PhotoListViewController.m
... // bla bla yada yada
[photoListViewController aMethodToPrintArrays];
Where am I doing wrong?
Thank you very much.
PS: Please
PPS: My english is not the best, please feel free to ask me to repeat.