So, here's the code for my cellForRowAtIndexPath:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifier"];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"identifier"]autorelease];
}
NSInteger artistIndex = 1; // 1
NSInteger albumIndex = 3; // 3
NSInteger dateIndex = 6; // 6
NSInteger imageIndex = 8; // 5
// ARTIST
CGRect frame = CGRectMake(59, 11, 244, 13);
UILabel *label = [[UILabel alloc]initWithFrame:frame];
label.font = [UIFont boldSystemFontOfSize:13];
label.textColor = [UIColor blackColor];
label.text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:artistIndex];
[cell addSubview:label];
// ALBUM (more like description...
frame = CGRectMake(60, 30, 244, 11);
label = [[UILabel alloc]initWithFrame:frame];
label.font = [UIFont boldSystemFontOfSize:11];
label.textColor = [UIColor darkGrayColor];
label.text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:albumIndex];
[cell addSubview:label];
// DATE
frame = CGRectMake(59, 49, 244, 10);
label = [[UILabel alloc]initWithFrame:frame];
label.font = [UIFont fontWithName:@"Helvetica" size:10.0];
label.textColor = [UIColor darkGrayColor];
label.textAlignment = UITextAlignmentRight;
label.text = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:dateIndex];
[cell addSubview:label];
// IMAGE
UIImageView *imageView = [[UIImageView alloc]init];
imageView.image = [[musicList.list objectAtIndex:indexPath.row] objectAtIndex:imageIndex];
imageView.frame = CGRectMake(8,9,44,44);
[imageView.layer setMasksToBounds:YES];
[imageView.layer setCornerRadius:3.0];
[[cell contentView] addSubview:imageView];
[imageView release];
[label release];
return cell;
}
To explain what's going on, basically it just taps into an array that stores strings for everything except for index 8 (which stores a UIImage).
I have no variables set to autorelease (mostly because I don't really understand autorelease just yet lol)
Anyways, when scrolling through the app, it will slow down progressively (mostly because of the UIImage, but also in part because of the labels and frames).
Is there anyway to manage my memory better? Also, is there a nicer way of coding this? I was thinking of making an array of UITableViewCells and just accessing those via cellForRowAtIndexPath.
So I would love for some suggestions, thanks guys.
See Question&Answers more detail:os