it works, but as soon as i scroll the tables they get mixed up
This indicates a problem with UITableViewCell
"recycling". You need to change the code of your tableview:cellforrowatindexpath:
in such a way that it sets cell.imageView.image
unconditionally, not only when the cell is created for the first time.
In addition, you could replace the chain of if
statements that check the calendar
for various specific values with a lookup in a dictionary, like this:
// This code goes into your viewDidLoad method. imageForCalendarType is an ivar
imageForCalendarType = @{
@"Live Music on Stage" : [UIImage imageNamed:@"music-notes-40x40.jpg"]
, @"Sports Shown on TV" : [UIImage imageNamed:@"sport-tv-40x40.jpg"]
, @"Fixed Event" : [UIImage imageNamed:@"fixed-40x40.jpg"]
};
Now you can use the image from the dictionary, like this:
// This goes into your tableview:cellforrowatindexpath: method
cell.imageView.image = imageForCalendarType[calendar];