【发布时间】:2015-02-05 12:21:27
【问题描述】:
好的,所以我一直在尝试解决我这几天遇到的问题,但没有成功。今天我找到了一个解决方案,但不是我的问题的完整解决方案。
这就是问题所在。
是这样开始的,请注意时间标签的对齐方式(左边的)
但是在表格第二次重新加载之后,或者当我来回切换选项卡时,它会更改为我希望它从一开始的样子。像这样。
这是在 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;
我从这篇帖子Changing the position of custom UIButton in custom UITableViewCell 中找到了一个解决方案,但问题是它会针对所有单元格进行更改。如您所见,我只需要更改几个单元格。请帮助我,我该怎么办...
编辑 1 的完整代码 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;
}
【问题讨论】:
-
试着把它放在 -(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
-
我已经试过了,求救@soulshined
-
您是否在描述单元格布局的笔尖或情节提要中使用自动布局?如果是这样设置 gameTimeLabel 框架可能是您的问题 - 您需要调整控制其位置的约束(相对于框架)。我还认为您应该在 GameInfoTableViewCell 本身的 layoutSubviews 中进行布局(如果不使用自动布局!)
标签: ios objective-c uitableview alignment