objective-c uitableview ios7 autolayout ios7.1

objective c - iOS7.0 e iOS 7.1 no respetan Dynamic Tableview Height



objective-c uitableview (0)

He usado el autolayout en varias implementaciones para UITableViewCell, el enfoque es dejar que el tamaño intrínseco defina el tamaño y que a su vez proporcione altura para las filas de la vista de tabla.

Extrañamente, el objetivo de iOS7 y superior con Autolayout en UITableViewCell no funciona como se desea.

Para solucionar uno de los otros problemas donde las celdas de tableview se comprimieron (en iOS8 y superior) agregué el siguiente control

if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_1 ){ self.tblvChatList.rowHeight = UITableViewAutomaticDimension; self.tblvChatList.estimatedRowHeight = 44; }

Los únicos otros métodos de vista de tabla que he usado son

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { return 1; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { if ([self.arrDataSource count] > ZERO_VALUE) { self.tblvChatList.backgroundView = nil; self.tblvChatList.separatorStyle = UITableViewCellSeparatorStyleNone; return [self.arrDataSource count]; } else { // Display a message when the table is empty if (!viewTableBackground) { self.viewTableBackground = [[UIView alloc] initWithFrame:self.tblvChatList.bounds]; UIImageView* imgConChatLogo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"IconConChatTheme"]]; [imgConChatLogo setContentMode:UIViewContentModeCenter]; [imgConChatLogo setTranslatesAutoresizingMaskIntoConstraints:NO]; UILabel* lblNoListDataError = [[UILabel alloc] initWithFrame:CGRectMake(ZERO_VALUE, ZERO_VALUE, (2*self.view.bounds.size.width)/3, self.view.bounds.size.height)]; lblNoListDataError.text = NSLocalizedString(@"STR_WRITE_SOMETHING_TO_MATCH", @"No data is currently available. Please pull down to refresh."); [lblNoListDataError setTranslatesAutoresizingMaskIntoConstraints:NO]; lblNoListDataError.textColor = [UIColor lightGrayColor]; lblNoListDataError.numberOfLines = ZERO_VALUE; lblNoListDataError.textAlignment = NSTextAlignmentCenter; lblNoListDataError.font = [Theme fontForRegularBody]; [lblNoListDataError sizeToFit]; [viewTableBackground addSubview:lblNoListDataError]; [viewTableBackground addSubview:imgConChatLogo]; [viewTableBackground addConstraint: [NSLayoutConstraint constraintWithItem:imgConChatLogo attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:viewTableBackground attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]]; [viewTableBackground addConstraint: [NSLayoutConstraint constraintWithItem:lblNoListDataError attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:viewTableBackground attribute:NSLayoutAttributeCenterX multiplier:1 constant:0]]; [viewTableBackground addConstraint: [NSLayoutConstraint constraintWithItem:imgConChatLogo attribute:NSLayoutAttributeBaseline relatedBy:NSLayoutRelationEqual toItem:viewTableBackground attribute:NSLayoutAttributeCenterY multiplier:1 constant:-10]]; [viewTableBackground addConstraint: [NSLayoutConstraint constraintWithItem:lblNoListDataError attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:viewTableBackground attribute:NSLayoutAttributeCenterY multiplier:1 constant:10]]; } self.tblvChatList.backgroundView = self.viewTableBackground; self.tblvChatList.separatorStyle = UITableViewCellSeparatorStyleNone; } return ZERO_VALUE; } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewCell* cell = nil; NSUInteger userId = [[NSUserDefaults standardUserDefaults] integerForKey:@"USER_ID"]; ChatMessage* message = (ChatMessage*)[self.arrDataSource objectAtIndex:indexPath.row]; if (userId == [message messageSenderId]) { static NSString* reuseIdentifierReceiverCell = @"ChatReceiverCustomCell"; cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierReceiverCell forIndexPath:indexPath]; [(ChatReceiverCell*)cell showMessage:message]; } else { static NSString* reuseIdentifierSenderCell = @"ChatSenderCustomCell"; cell = [tableView dequeueReusableCellWithIdentifier:reuseIdentifierSenderCell forIndexPath:indexPath]; // Configure the cell... [(ChatSenderCell*)cell showMessage:message]; } return cell; }

No he utilizado ni estimateHeightForRowAtIndexPath: ni heightForRowAtIndexPath: y dejo que el contenido decida la altura para tableviewRow.

  • Problema:

Por qué las celdas de TableView están comprimidas cuando se ejecutan en iOS7, iOS7.1 (simulador y dispositivos) pero se muestran perfectamente en iOS8 y superior para el mismo contenido para el mismo contenido.

Para solucionar este apretón, si implemento estimatedHeightForRowAtIndexPath: entonces no implementa heightForRowAtIndexPath: produce un bloqueo en iOS7. ¿Hay alguna manera de permitir que tableview infiera la altura de la fila del sistema de autodiseño en sí mismo (como derivado del tamaño del contenido intrínseco de UILabel, teniendo en cuenta el relleno extra ya que he agregado los márgenes requeridos)?

Las restricciones de autolayout para UILabel dentro de la celda son las siguientes