我有一個自定義單元格的表格。這個單元格有一個標籤,我希望在單元格中移動(如果條件成立)。爲什麼僅當第二次調用該單元格的cellForRowAtIndexPath方法時才更新標籤的位置?TableViewCell - 自定義單元格iOS - 內容
這是第一個問題。
第二個問題是如下: 定製細胞包含的視圖,在該視圖中以編程增加圖象。如果我在表格中有兩個部分,在滾動表格後,第一部分中的第一個單元格的圖像出現在第二部分的第一個單元格中。爲什麼?
這是代碼提前
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *idDettCal = @"cellaVotoCalciatore";
NSString *idRiepilogo = @"riepilogoCell";
NSString *idTotali = @"bonusTotaliCell";
//Dictionary per Titolari e Panchinari
NSDictionary *calciatore = [[NSDictionary alloc] init];
if (indexPath.section == 0 || indexPath.section == 1) {
foaVotoCalciatoreCell *cell = (foaVotoCalciatoreCell *)[tableView dequeueReusableCellWithIdentifier:idDettCal];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:idDettCal owner:self options:nil];
cell = [nib objectAtIndex:0];
}
//TITOLARI
if (indexPath.section == 0) {
calciatore = [titolari objectAtIndex:indexPath.row];
}
//PANCHINARI
else if (indexPath.section == 1) {
calciatore = [panchinari objectAtIndex:indexPath.row];
}
NSString *calciatoreStr =
[NSString stringWithFormat:@"%@%@%@%@",
[calciatore objectForKey:@"CALCIATORE"],
@" (",
[[calciatore objectForKey:@"SQUADRA"] substringToIndex:3],
@")"];
NSString *imgRuolo =
[NSString stringWithFormat:@"%@%@",
[calciatore objectForKey:@"RUOLO"],
@".jpg"];
cell.ruolo.image = [UIImage imageNamed:imgRuolo];
NSDictionary *dettaglioVoto = [[NSDictionary alloc] init];
UIImageView *imageIcona;
CGFloat offset;
dettaglioVoto = [calciatore objectForKey:@"VOTO_STM"];
offset = 0;
for (NSString *icona in dettaglioVoto) {
if ([icona isEqualToString: @"AMMONITO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"amm.png"]];
}
else if ([icona isEqualToString: @"GOL_FATTO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"golfatto.png"]];
}
else if ([icona isEqualToString: @"GOL_SUBITO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"golsubito.png"]];
}
else if ([icona isEqualToString: @"ENTRATO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"entrato.png"]];
}
else if ([icona isEqualToString: @"USCITO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"uscito.png"]];
}
else if ([icona isEqualToString: @"ESPULSO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"esp.png"]];
}
else if ([icona isEqualToString: @"ASSIST"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"assist.png"]];
}
else if ([icona isEqualToString: @"ASSIST_FERMO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"assistf.png"]];
}
else if ([icona isEqualToString: @"RIGORE_SEGNATO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rigoresegnato.png"]];
}
else if ([icona isEqualToString: @"RIGORE_SBAGLIATO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rigoresbagliato.png"]];
}
else if ([icona isEqualToString: @"RIGORE_PARATO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"rigoreparato.png"]];
}
else if ([icona isEqualToString: @"AUTOGOL"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"autogol.png"]];
}
else if ([icona isEqualToString: @"GOL_PARTITA"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"golvittoria.png"]];
}
else if ([icona isEqualToString: @"GOL_PAREGGIO"]) {
imageIcona = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"golpareggio.png"]];
}
imageIcona.frame = CGRectMake(offset, 0, imageIcona.frame.size.width, imageIcona.frame.size.height);
offset = imageIcona.frame.size.width + offset + 2;
[cell.iconeDettaglio addSubview: imageIcona];
}
if (offset == 0) {
cell.calciatore.frame = CGRectMake(cell.calciatore.frame.origin.x, 14, cell.calciatore.frame.size.width, cell.calciatore.frame.size.height);
cell.iconeDettaglio.hidden = YES;
}
cell.calciatore.text = calciatoreStr;
cell.votoIniziale.text = [calciatore objectForKey:@"VOTO_PRNT"];
cell.votoFinale.text = [calciatore objectForKey:@"VOTO_PRNT_TOT"];
return cell;
}
//La giornata è calcolata. Sezione 2 = BONUS e TOTALI
else if (variabiliGlobali.gioCalcolata && indexPath.section == 2) {
NSDictionary *totaliVal;
NSDictionary *totaliTip;
totaliVal = [logCalValore objectAtIndex:indexPath.row];
totaliTip = [logCalTipo objectAtIndex:indexPath.row];
foaBonusTotaliCell *cell = (foaBonusTotaliCell *)[tableView dequeueReusableCellWithIdentifier:idTotali];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:idTotali owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.tipoBonusLabel.text = totaliTip;
cell.totaleLabel.text = totaliVal;
return cell;
}
else {
NSDictionary *riepilogoVal;
NSDictionary *riepilogoTip;
riepilogoVal = [logForValore objectAtIndex:indexPath.row];
riepilogoTip = [logForTipo objectAtIndex:indexPath.row];
foaRiepilogoCell *cell = (foaRiepilogoCell *)[tableView dequeueReusableCellWithIdentifier:idRiepilogo];
if (cell == nil)
{
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:idRiepilogo owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.voceRiepilogoLabel.text = riepilogoTip;
cell.valoreRiepilogoLabel.text = riepilogoVal;
return cell;
}
}
感謝。
您需要發佈相關代碼,以便我們可以幫助您解決問題。 – rmaddy
我已發佈代碼 –
我已插入圖片。第一個是表格出現的時候。第二個是在滾動之後。 –