My tableviewcell has around 64 elements (32 buttons and 32 images). Each one is small (29*29) and they are stacked like a calendar so they fit within a (320*200) view. When the view first loads with the code below it works PERFECTLY! Then when you scroll down and scroll back up some of the first elements/last couple of elements get messed up. Some of the images done load, etc. I am assuming it's because there are 36 if statements running everytime the cell is loaded and that can probably cause some issues. What can I do so this does not happen any more? Can I shrink these if statements into only a couple? Thanks!
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"scheduleDaysTableViewCell2" forIndexPath:indexPath];
NSLog(@"cellForRowAtIndexPath");
// Configure the cell...
PFObject *object = self.octoberArray[indexPath.section][indexPath.row];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.separatorInset = UIEdgeInsetsZero;
UIButton *date1Button = (UIButton *) [cell viewWithTag:719];
UIButton *date2Button = (UIButton *) [cell viewWithTag:729];
UIButton *date3Button = (UIButton *) [cell viewWithTag:739];
UIButton *date4Button = (UIButton *) [cell viewWithTag:749];
UIButton *date5Button = (UIButton *) [cell viewWithTag:19];
UIButton *date6Button = (UIButton *) [cell viewWithTag:29];
UIButton *date7Button = (UIButton *) [cell viewWithTag:39];
UIButton *date8Button = (UIButton *) [cell viewWithTag:49];
UIButton *date9Button = (UIButton *) [cell viewWithTag:59];
UIButton *date10Button = (UIButton *) [cell viewWithTag:69];
UIButton *date11Button = (UIButton *) [cell viewWithTag:79];
UIButton *date12Button = (UIButton *) [cell viewWithTag:89];
UIButton *date13Button = (UIButton *) [cell viewWithTag:99];
UIButton *date14Button = (UIButton *) [cell viewWithTag:109];
UIButton *date15Button = (UIButton *) [cell viewWithTag:119];
UIButton *date16Button = (UIButton *) [cell viewWithTag:129];
UIButton *date17Button = (UIButton *) [cell viewWithTag:139];
UIButton *date18Button = (UIButton *) [cell viewWithTag:149];
UIButton *date19Button = (UIButton *) [cell viewWithTag:159];
UIButton *date20Button = (UIButton *) [cell viewWithTag:169];
UIButton *date21Button = (UIButton *) [cell viewWithTag:179];
UIButton *date22Button = (UIButton *) [cell viewWithTag:189];
UIButton *date23Button = (UIButton *) [cell viewWithTag:199];
UIButton *date24Button = (UIButton *) [cell viewWithTag:209];
UIButton *date25Button = (UIButton *) [cell viewWithTag:219];
(...)
UIButton *date36Button = (UIButton *) [cell viewWithTag:329];
UIImageView *date1Image = (UIImageView *) [cell viewWithTag:718];
UIImageView *date2Image = (UIImageView *) [cell viewWithTag:728];
UIImageView *date3Image = (UIImageView *) [cell viewWithTag:738];
UIImageView *date4Image = (UIImageView *) [cell viewWithTag:748];
UIImageView *date5Image = (UIImageView *) [cell viewWithTag:18];
UIImageView *date6Image = (UIImageView *) [cell viewWithTag:28];
UIImageView *date7Image = (UIImageView *) [cell viewWithTag:38];
UIImageView *date8Image = (UIImageView *) [cell viewWithTag:48];
UIImageView *date9Image = (UIImageView *) [cell viewWithTag:58];
UIImageView *date10Image = (UIImageView *) [cell viewWithTag:68];
UIImageView *date11Image = (UIImageView *) [cell viewWithTag:78];
UIImageView *date12Image = (UIImageView *) [cell viewWithTag:88];
UIImageView *date13Image = (UIImageView *) [cell viewWithTag:98];
UIImageView *date14Image = (UIImageView *) [cell viewWithTag:108];
UIImageView *date15Image = (UIImageView *) [cell viewWithTag:118];
UIImageView *date16Image = (UIImageView *) [cell viewWithTag:128];
UIImageView *date17Image = (UIImageView *) [cell viewWithTag:138];
UIImageView *date18Image = (UIImageView *) [cell viewWithTag:148];
UIImageView *date19Image = (UIImageView *) [cell viewWithTag:158];
UIImageView *date20Image = (UIImageView *) [cell viewWithTag:168];
UIImageView *date21Image = (UIImageView *) [cell viewWithTag:178];
UIImageView *date22Image = (UIImageView *) [cell viewWithTag:188];
UIImageView *date23Image = (UIImageView *) [cell viewWithTag:198];
UIImageView *date24Image = (UIImageView *) [cell viewWithTag:208];
UIImageView *date25Image = (UIImageView *) [cell viewWithTag:218];
(...)
UIImageView *date36Image = (UIImageView *) [cell viewWithTag:328];
NSString *Date1 = object[@"Date1"];
NSString *Date2 = object[@"Date2"];
NSString *Date3 = object[@"Date3"];
NSString *Date4 = object[@"Date4"];
NSString *Date5 = object[@"Date5"];
NSString *Date6 = object[@"Date6"];
NSString *Date7 = object[@"Date7"];
NSString *Date8 = object[@"Date8"];
NSString *Date9 = object[@"Date9"];
NSString *Date10 = object[@"Date10"];
NSString *Date11 = object[@"Date11"];
NSString *Date12 = object[@"Date12"];
NSString *Date13 = object[@"Date13"];
NSString *Date14 = object[@"Date14"];
NSString *Date15 = object[@"Date15"];
NSString *Date16 = object[@"Date16"];
NSString *Date17 = object[@"Date17"];
NSString *Date18 = object[@"Date18"];
NSString *Date19 = object[@"Date19"];
NSString *Date20 = object[@"Date20"];
NSString *Date21 = object[@"Date21"];
NSString *Date22 = object[@"Date22"];
NSString *Date23 = object[@"Date23"];
NSString *Date24 = object[@"Date24"];
NSString *Date25 = object[@"Date25"];
(...)
NSString *Date36 = object[@"Date36"];
//This is where I am separating the number from the word.
NSString *date1 = [[Date1 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date2 = [[Date2 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date3 = [[Date3 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date4 = [[Date4 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date5 = [[Date5 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date6 = [[Date6 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date7 = [[Date7 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date8 = [[Date8 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date9 = [[Date9 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date10 = [[Date10 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date11 = [[Date11 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date12 = [[Date12 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date13 = [[Date13 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date14 = [[Date14 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date15 = [[Date15 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date16 = [[Date16 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date17 = [[Date17 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date18 = [[Date18 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date19 = [[Date19 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date20 = [[Date20 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date21 = [[Date21 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date22 = [[Date22 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date23 = [[Date23 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date24 = [[Date24 componentsSeparatedByString:@" "] objectAtIndex:0];
NSString *date25 = [[Date25 componentsSeparatedByString:@" "] objectAtIndex:0];
(...)
NSString *date36 = [[Date36 componentsSeparatedByString:@" "] objectAtIndex:0];
if ([Date1 isEqual:@"0"]) {
//Alpha 0
[date1Button setTitle:@"" forState:UIControlStateNormal];
date1Image.alpha = 0.0;
} else if ([Date1 containsString:@"GREY"]) {
//Grey
[date1Button setTitle:date1 forState:UIControlStateNormal];
date1Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date1Button setTitle:date1 forState:UIControlStateNormal];
date1Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date2 isEqual:@"0"]) {
//Alpha 0
[date2Button setTitle:@"" forState:UIControlStateNormal];
date2Image.alpha = 0.0;
} else if ([Date2 containsString:@"GREY"]) {
//Grey
[date2Button setTitle:date2 forState:UIControlStateNormal];
date2Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date2Button setTitle:date2 forState:UIControlStateNormal];
date2Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date3 isEqual:@"0"]) {
//Alpha 0
[date3Button setTitle:@"" forState:UIControlStateNormal];
date3Image.alpha = 0.0;
} else if ([Date3 containsString:@"GREY"]) {
//Grey
[date3Button setTitle:date3 forState:UIControlStateNormal];
date3Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date3Button setTitle:date3 forState:UIControlStateNormal];
date3Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date4 isEqual:@"0"]) {
//Alpha 0
[date4Button setTitle:@"" forState:UIControlStateNormal];
date4Image.alpha = 0.0;
} else if ([Date4 containsString:@"GREY"]) {
//Grey
[date4Button setTitle:date4 forState:UIControlStateNormal];
date4Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date4Button setTitle:date4 forState:UIControlStateNormal];
date4Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date5 isEqual:@"0"]) {
//Alpha 0
[date5Button setTitle:@"" forState:UIControlStateNormal];
date5Image.alpha = 0.0;
} else if ([Date5 containsString:@"GREY"]) {
//Grey
[date5Button setTitle:date5 forState:UIControlStateNormal];
date5Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date5Button setTitle:date5 forState:UIControlStateNormal];
date5Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date6 isEqual:@"0"]) {
//Alpha 0
[date6Button setTitle:@"" forState:UIControlStateNormal];
date6Image.alpha = 0.0;
} else if ([Date6 containsString:@"GREY"]) {
//Grey
[date6Button setTitle:date6 forState:UIControlStateNormal];
date6Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date6Button setTitle:date6 forState:UIControlStateNormal];
date6Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date7 isEqual:@"0"]) {
//Alpha 0
[date7Button setTitle:@"" forState:UIControlStateNormal];
date7Image.alpha = 0.0;
} else if ([Date7 containsString:@"GREY"]) {
//Grey
[date7Button setTitle:date7 forState:UIControlStateNormal];
date7Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date7Button setTitle:date7 forState:UIControlStateNormal];
date7Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date8 isEqual:@"0"]) {
//Alpha 0
[date8Button setTitle:@"" forState:UIControlStateNormal];
date8Image.alpha = 0.0;
} else if ([Date8 containsString:@"GREY"]) {
//Grey
[date8Button setTitle:date8 forState:UIControlStateNormal];
date8Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date8Button setTitle:date8 forState:UIControlStateNormal];
date8Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date9 isEqual:@"0"]) {
//Alpha 0
[date9Button setTitle:@"" forState:UIControlStateNormal];
date9Image.alpha = 0.0;
} else if ([Date9 containsString:@"GREY"]) {
//Grey
[date9Button setTitle:date9 forState:UIControlStateNormal];
date9Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date9Button setTitle:date9 forState:UIControlStateNormal];
date9Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date10 isEqual:@"0"]) {
//Alpha 0
[date10Button setTitle:@"" forState:UIControlStateNormal];
date10Image.alpha = 0.0;
} else if ([Date10 containsString:@"GREY"]) {
//Grey
[date10Button setTitle:date10 forState:UIControlStateNormal];
date10Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date10Button setTitle:date10 forState:UIControlStateNormal];
date10Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date11 isEqual:@"0"]) {
//Alpha 0
[date11Button setTitle:@"" forState:UIControlStateNormal];
date11Image.alpha = 0.0;
} else if ([Date11 containsString:@"GREY"]) {
//Grey
[date11Button setTitle:date11 forState:UIControlStateNormal];
date11Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date11Button setTitle:date11 forState:UIControlStateNormal];
date11Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date12 isEqual:@"0"]) {
//Alpha 0
[date12Button setTitle:@"" forState:UIControlStateNormal];
date12Image.alpha = 0.0;
} else if ([Date12 containsString:@"GREY"]) {
//Grey
[date12Button setTitle:date12 forState:UIControlStateNormal];
date12Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date12Button setTitle:date12 forState:UIControlStateNormal];
date12Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date13 isEqual:@"0"]) {
//Alpha 0
[date13Button setTitle:@"" forState:UIControlStateNormal];
date13Image.alpha = 0.0;
} else if ([Date13 containsString:@"GREY"]) {
//Grey
[date13Button setTitle:date13 forState:UIControlStateNormal];
date13Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date13Button setTitle:date13 forState:UIControlStateNormal];
date13Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date14 isEqual:@"0"]) {
//Alpha 0
[date14Button setTitle:@"" forState:UIControlStateNormal];
date14Image.alpha = 0.0;
} else if ([Date14 containsString:@"GREY"]) {
//Grey
[date14Button setTitle:date14 forState:UIControlStateNormal];
date14Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date14Button setTitle:date14 forState:UIControlStateNormal];
date14Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date15 isEqual:@"0"]) {
//Alpha 0
[date15Button setTitle:@"" forState:UIControlStateNormal];
date15Image.alpha = 0.0;
} else if ([Date15 containsString:@"GREY"]) {
//Grey
[date15Button setTitle:date15 forState:UIControlStateNormal];
date15Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date15Button setTitle:date15 forState:UIControlStateNormal];
date15Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date16 isEqual:@"0"]) {
//Alpha 0
[date16Button setTitle:@"" forState:UIControlStateNormal];
date16Image.alpha = 0.0;
} else if ([Date16 containsString:@"GREY"]) {
//Grey
[date16Button setTitle:date16 forState:UIControlStateNormal];
date16Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date16Button setTitle:date16 forState:UIControlStateNormal];
date16Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date17 isEqual:@"0"]) {
//Alpha 0
[date17Button setTitle:@"" forState:UIControlStateNormal];
date17Image.alpha = 0.0;
} else if ([Date17 containsString:@"GREY"]) {
//Grey
[date17Button setTitle:date17 forState:UIControlStateNormal];
date17Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date17Button setTitle:date17 forState:UIControlStateNormal];
date17Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date18 isEqual:@"0"]) {
//Alpha 0
[date18Button setTitle:@"" forState:UIControlStateNormal];
date18Image.alpha = 0.0;
} else if ([Date18 containsString:@"GREY"]) {
//Grey
[date18Button setTitle:date18 forState:UIControlStateNormal];
date18Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date18Button setTitle:date18 forState:UIControlStateNormal];
date18Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date19 isEqual:@"0"]) {
//Alpha 0
[date19Button setTitle:@"" forState:UIControlStateNormal];
date19Image.alpha = 0.0;
} else if ([Date19 containsString:@"GREY"]) {
//Grey
[date19Button setTitle:date19 forState:UIControlStateNormal];
date19Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date19Button setTitle:date19 forState:UIControlStateNormal];
date19Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date20 isEqual:@"0"]) {
//Alpha 0
[date20Button setTitle:@"" forState:UIControlStateNormal];
date20Image.alpha = 0.0;
} else if ([Date20 containsString:@"GREY"]) {
//Grey
[date20Button setTitle:date20 forState:UIControlStateNormal];
date20Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date20Button setTitle:date20 forState:UIControlStateNormal];
date20Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date21 isEqual:@"0"]) {
//Alpha 0
[date21Button setTitle:@"" forState:UIControlStateNormal];
date21Image.alpha = 0.0;
} else if ([Date21 containsString:@"GREY"]) {
//Grey
[date21Button setTitle:date21 forState:UIControlStateNormal];
date21Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date21Button setTitle:date21 forState:UIControlStateNormal];
date21Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date22 isEqual:@"0"]) {
//Alpha 0
[date22Button setTitle:@"" forState:UIControlStateNormal];
date22Image.alpha = 0.0;
} else if ([Date22 containsString:@"GREY"]) {
//Grey
[date22Button setTitle:date22 forState:UIControlStateNormal];
date22Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date22Button setTitle:date22 forState:UIControlStateNormal];
date22Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date23 isEqual:@"0"]) {
//Alpha 0
[date23Button setTitle:@"" forState:UIControlStateNormal];
date23Image.alpha = 0.0;
} else if ([Date23 containsString:@"GREY"]) {
//Grey
[date23Button setTitle:date23 forState:UIControlStateNormal];
date23Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date23Button setTitle:date23 forState:UIControlStateNormal];
date23Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date24 isEqual:@"0"]) {
//Alpha 0
[date24Button setTitle:@"" forState:UIControlStateNormal];
date24Image.alpha = 0.0;
} else if ([Date24 containsString:@"GREY"]) {
//Grey
[date24Button setTitle:date24 forState:UIControlStateNormal];
date24Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date24Button setTitle:date24 forState:UIControlStateNormal];
date24Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
if ([Date25 isEqual:@"0"]) {
//Alpha 0
[date25Button setTitle:@"" forState:UIControlStateNormal];
date25Image.alpha = 0.0;
} else if ([Date25 containsString:@"GREY"]) {
//Grey
[date25Button setTitle:date25 forState:UIControlStateNormal];
date25Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date25Button setTitle:date25 forState:UIControlStateNormal];
date25Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
(...)
if ([Date36 isEqual:@"0"]) {
//Alpha 0
[date36Button setTitle:@"" forState:UIControlStateNormal];
date36Image.alpha = 0.0;
} else if ([Date36 containsString:@"GREY"]) {
//Grey
[date36Button setTitle:date36 forState:UIControlStateNormal];
date36Image.image = [UIImage imageNamed:@"greyLittleCircleForCalendar.png"];
} else {
//Gold
[date36Button setTitle:date36 forState:UIControlStateNormal];
date36Image.image = [UIImage imageNamed:@"goldLittleCircleForCalendar.png"];
}
return cell;
}
Aucun commentaire:
Enregistrer un commentaire