Domanda

Ho una forma piuttosto complessa che viene disposta in un UITableView. Questo modulo ha un certo UICollectionView all'interno di una cella di vista tabella e anche alcuni raccoglitori che presentano lo stesso modo in cui esegue l'app Calendario:

immagine

Ora quando lo faccio sulla mia app, uno dei UICollectionView che ho più alto di come ha iniziato - e continua ad andare (ho aggiunto un bordo rosso per assicurarmi che fosse il UICollectionView che è stato ridimensionato): .

Immagine

Ho provato il debug della proprietà di vista UICollectionView, ma non cambia mai (ed è Getter / Setter non viene chiamato più di quello che mi aspettavo) - anche se quando lo stampato su cellForRowAtIndexPath si presenta ridimensionato. C'è un modo in cui posso eseguire il debug di questo meglio o avere qualcuno nella stessa situazione?

Grazie!

Codice:

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
//self.campos is a dictionary with sections and rows stored
    NSMutableArray *infoCampos = [[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"];
NSDictionary *infoCampo = [infoCampos objectAtIndex:indexPath.row];

if ([[infoCampo objectForKey:@"nome"] isEqualToString:@"dosePorComprimido"]) {
    //Remove picker cell if finds it
    for (infoCampo in infoCampos) {
        if ([infoCampo objectForKey:@"view"] == self.dosagemMedicamento.view) {
            [infoCampos removeObject:infoCampo];
            [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
            [tableView deselectRowAtIndexPath:indexPath animated:YES];
            return;
        }
    }

    //Insert new cell
    infoCampo = [infoCampos objectAtIndex:indexPath.row];
    [infoCampos addObject:@{@"tipo":@5, @"view":self.dosagemMedicamento.view, @"nome":[infoCampo objectForKey:@"nome"]}];
    [tableView reloadSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationAutomatic];
    [self.dosagemMedicamento.view.superview addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|[pickerDosagem]|" options:0 metrics:nil views:@{@"pickerDosagem":self.dosagemMedicamento.view}]];
}
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
    UIView *view;

    if ([infoCampo objectForKey:@"view"]) {
        view = (UIView *) [infoCampo objectForKey:@"view"];
        return view.frame.size.height;
    }

    return 44.0f;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:

(NSIndexPath *)indexPath
{
    UITableViewCell *cell;
    NSMutableDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
    UIView *view;

cell = [tableView dequeueReusableCellWithIdentifier:[[infoCampo objectForKey:@"nome"] stringByAppendingString:@"ViewLinhaCellView"] forIndexPath:indexPath];

        view = [cell viewWithTag:1];

        [view addSubview:[infoCampo objectForKey:@"view"]];

return cell;
}
.

Modifica: Hai dimenticato di menzionare che non sto aggiornando la vista tabella con ReloadData ma solo le sezioni / righe necessarie con ReloadRowSatIndexpaths e Reloadsections. Quindi questo rende ancora più strano perché non sto ricaricando quella particolare sezione.

Modifica 2: Aggiunta Source Data EURY E Delegate Codice

È stato utile?

Soluzione

Credo che il tuo problema sia qui, nell'attuazione del tableView:heightForRowAtIndexPath:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
    UIView *view;

    if ([infoCampo objectForKey:@"view"]) {
        view = (UIView *) [infoCampo objectForKey:@"view"];
        return view.frame.size.height;
    }

    return 44.0f;
}
.

La vista probabilmente viene ridimensionata dal layout automatico o dalla sua maschera di esecuzione.Non ci sono abbastanza informazioni qui per dire esattamente perché, ma le viste da tavolo e il layout automatico possono avere qualche comportamento divertente.Raccomando solo restituire un'altezza impostata, piuttosto che ottenere l'altezza dalla vista:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *infoCampo = [[[self.campos objectAtIndex:indexPath.section] objectForKey:@"campos"] objectAtIndex:indexPath.row];
    UIView *view;

    if ([infoCampo objectForKey:@"view"]) {
        if ([infoCampo objectForKey:@"viewHeight"]) {
            return [[infoCampo objectForKey:@"viewHeight"] floatValue];
        } else {
            return 216.0f;
        }
    }

    return 44.0f;
}
.

Il tasto viewHeight consente di specificare un'altezza personalizzata per la visualizzazione di ciascuna cella, ma questa implementazione restituisce anche un'altezza predefinita (216) che è l'altezza standard per le viste del selezionatore.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top