Ok so i have been trying to fix a problem that i got for a couple of days now without success. Today i found a solution but not a FULL solution to my problem.
So this is the problem.
It starts like this, please note the alignment of the time labels(the ones to the left)
But after the table reloads for the second time OR when i switch tabs back and forth it THEN changes to what i want it to look like from the beginning. Like this.
This is the code that does this inside cellForRowAtIndexPath:
if ([gameInfoObject.GameTime isEqual: @"FT"] || ([gameInfoObject.GameTime rangeOfString:@":"].location != NSNotFound)) { // CHeck to see if its FT or string contains ":" then hide liveB
cell.liveButton.hidden = YES;
CGRect frame = cell.gameTimeLabel.frame;
frame.origin.x= 27; // move the label 10pts to the left since no image will be present
cell.gameTimeLabel.frame= frame;
I found a solution from this post Changing the position of custom UIButton in custom UITableViewCell but the problem is that it changes FOR ALL THE CELLS. As you can see i only need it to change for a few cells. Please help me what can i do im out of ideas...
EDIT 1 the whole code for cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *identifier = @"Cell";
GamesInfoTableViewCell *cell = (GamesInfoTableViewCell *)[tableView dequeueReusableCellWithIdentifier:identifier];
// Configure the cell...
GameInfo *gameInfoObject;
gameInfoObject =[gamesInfoArray objectAtIndex:indexPath.row];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.backgroundColor = TABLECOLOR;
cell.homeTeamLabel.textColor = TEXT;
cell.awayTeamLabel.textColor = TEXT;
cell.gameTimeLabel.textColor = TEXT;
cell.homeTeamLabel.text = gameInfoObject.HomeTeam;
cell.awayTeamLabel.text = gameInfoObject.AwayTeam;
cell.homeTeamScoreLabel.text = gameInfoObject.HomeScore;
cell.awayTeamScoreLabel.text = gameInfoObject.AwayScore;
cell.liveButton.image = [UIImage imageNamed:@"1675447.png"]; //Load the green image
if ([gameInfoObject.GameTime isEqual: @"FT"] || ([gameInfoObject.GameTime rangeOfString:@":"].location != NSNotFound)) { // CHeck to see if its FT or string contains ":" then hide liveB
cell.liveButton.hidden = YES;
CGRect frame = cell.gameTimeLabel.frame;
frame.origin.x= 27; // move the label 10pts to the left since no image will be present
cell.gameTimeLabel.frame= frame;
}
else
cell.liveButton.hidden = NO;
if (([gameInfoObject.GameTime rangeOfString:@":"].location != NSNotFound)) {
cell.accessoryType = FALSE;
cell.userInteractionEnabled = NO;
cell.homeTeamScoreLabel.hidden = YES;
cell.awayTeamScoreLabel.hidden = YES;
}
cell.gameTimeLabel.text = gameInfoObject.GameTime;
return cell;
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…