问题描述
行,所以我一直在试图解决这个问题,我得到了几天的,现在都没有成功的一个问题。今天,我发现了一个解决方案,但不是一个完整的解决我的问题。
所以,这就是问题所在。
它开始是这样,请注意时间标记对齐(到左边的)
但是表重新加载第二次后,或当我切换标签来回然后它变成什么,我希望它看起来像从一开始。就像这一点。
这是在code里面做到这一点的cellForRowAtIndexPath:
如果([gameInfoObject.GameTime的isEqual:@金融时报] ||([gameInfoObject.GameTime rangeOfString:@:]!=位置NSNotFound)){//检查,看看它的FT或字符串包含:然后隐藏liveB
cell.liveButton.hidden = YES;
CGRect帧= cell.gameTimeLabel.frame;
frame.origin.x = 27; //移动标签10pts到左边,因为没有图像将是present
cell.gameTimeLabel.frame =帧;
我觉得从这个帖子的解决方案Changing自定义的UIButton的自定义UITableViewCell 但问题的立场是,它改变了所有单元。正如你所看到的我只需要它改变了几个细胞。请帮我我该怎么做即时通讯的想法...
修改1整个$ C $下 的cellForRowAtIndexPath
- (定义UITableViewCell *)的tableView:(UITableView的*)的tableView的cellForRowAtIndexPath:(NSIndexPath *)indexPath {
静态的NSString *标识符= @细胞;
GamesInfoTableViewCell *电池=(GamesInfoTableViewCell *)的tableView dequeueReusableCellWithIdentifier:标识]。
//配置单元...
的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]; //将绿色形象
如果([gameInfoObject.GameTime的isEqual:@金融时报] ||([gameInfoObject.GameTime rangeOfString:@:]!=位置NSNotFound)){//检查,看看它的FT或字符串包含:再隐藏liveB
cell.liveButton.hidden = YES;
CGRect帧= cell.gameTimeLabel.frame;
frame.origin.x = 27; //移动标签10pts到左边,因为没有图像将是present
cell.gameTimeLabel.frame =帧;
}
其他
cell.liveButton.hidden = NO;
如果(([gameInfoObject.GameTime rangeOfString:@:]!=位置NSNotFound)){
cell.accessoryType = FALSE;
cell.userInteractionEnabled = NO;
cell.homeTeamScoreLabel.hidden = YES;
cell.awayTeamScoreLabel.hidden = YES;
}
cell.gameTimeLabel.text = gameInfoObject.GameTime;
返回细胞;
}
刚查了indexpath.row
如果(indexpath.row == 2){
cell.liveButton.hidden = YES;
CGRect帧= cell.gameTimeLabel.frame;
frame.origin.x = 27; //移动标签10pts到左边,因为没有图像将是present
cell.gameTimeLabel.frame =框架;}
编辑---
它仍然不是100%清楚究竟是什么问题,但继承人几件事情你可以试试。
- 重置在layoutSubviews布局
[self.view setNeedsLayout];
- 视图加载后开始重新加载的UITableView实例的数据。
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;
}
Just check for the indexpath.row
if (indexpath.row == 2){
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;}
EDIT ---
Its still not 100% clear what exactly the problem is but heres a couple of things you could try.
- Reset the layout in layoutSubviews
[self.view setNeedsLayout];
- Reload the data of the UITableView instance after the view loads initially.
这篇关于改变一个UILabel的位置为自定义的UITableViewCell的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!