Изменение позиции UILabel для пользовательского UITableVIewCell
Хорошо, поэтому я пытался исправить проблему, которую я получил уже пару дней без успеха. Сегодня я нашел решение, но не ПОЛНОЕ решение моей проблемы.
Итак, это проблема.
Он начинается следующим образом: обратите внимание на выравнивание меток времени (слева)
![Screenshot 1]()
Но после повторной загрузки таблицы во второй раз или когда я переключаю вкладки назад и вперед, THEN меняет то, что я хочу, чтобы оно выглядело с самого начала. Как это.
![Screenshot 2]()
Это код, который делает это внутри 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;
Я нашел решение из этого сообщения Изменение позиции пользовательского UIButton в пользовательском 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;
}
Ответы
Ответ 1
Просто проверьте для 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 ---
Его все еще не на 100% ясно, что именно проблема, но вот несколько вещей, которые вы могли бы попробовать.
- Reset макет в layoutSubviews
[self.view setNeedsLayout];
- Перезагрузите данные экземпляра UITableView после того, как первоначально загрузится представление.