好吧,所以我一直在努力解决一个问题,我得到了几天没有成功。今天,我发现了一个解决方案,但没有解决我的问题。更改自定义UITableVIewCell的UILabel的位置
所以这是问题所在。
它开始这样的,请注意时间标签(那些向左)对齐
但第二次表重装后或当我切换标签它来回变化,然后变成我想从一开始就看起来的样子。喜欢这个。
这是做这里面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的解决方案的代码,但问题是,它改变了所有单元。正如你所看到的,我只需要它改变几个单元格。请帮我我该怎么做IM的想法......
EDIT 1cellForRowAtIndexPath
- (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;
}
尝试把它放在 - (空)的tableView:(UITableView的*)的tableView willDisplayCell:(*的UITableViewCell)单元forRowAtIndexPath:(NSIndexPath *)indexPath { – soulshined 2014-12-07 21:42:12
我已经尝试过了,Dst的帮助,您使用的@soulshined – 2014-12-07 22:03:52
在描述单元格布局的笔尖或故事板中自动布局?如果这样设置gameTimeLabel框架可能是您的问题 - 您需要调整控制其位置的约束(vs框架)。我也认为你应该在GameInfoTableViewCell本身的layoutSubviews(如果不使用自动布局!) – TomSwift 2014-12-09 16:37:08