好吧,所以我一直在努力解決一個問題,我得到了幾天沒有成功。今天,我發現了一個解決方案,但沒有解決我的問題。更改自定義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