I have two UILabel aside from UICell that contains dynamic text, so I need to resize its frame to fit the content for which im uses the [string sizeWithFont] method to calculate the height of the label view frame inside the TableView heightForRowAtIndexPath to set the cell height according to the height of the inscription. Now the problem is when I look at the table, the label inside the cell starts to decrease if I remove the [label sizeToFit] method, which it does not compress, but because my labels overlap, which looks very dirty. Where am I wrong, please help me ..
here is my code for cellRowAtIndexPath method
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { NSLog(@"cell"); BOOL ente = FALSE; static NSString *CellIdentifier = @"CustomCell"; CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil]; for (id currentObject in topLevelObjects){ if ([currentObject isKindOfClass:[UITableViewCell class]]){ cell = (CustomCell *) currentObject; ente = TRUE; break; } } } cell.title.text = [mainEventArray objectAtIndex:[indexPath row]]; cell.dataTime.text = [mainEventTimeArray objectAtIndex:[indexPath row]];
and for heightForRowAtIndexPath method
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *CellIdentifier = @"CustomCell"; CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; { if (cell == nil) { NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil]; for (id currentObject in topLevelObjects){ if ([currentObject isKindOfClass:[UITableViewCell class]]){ cell = (CustomCell *) currentObject; break; } } } } CGSize size1 = [[mainEventArray objectAtIndex:[indexPath row]] sizeWithFont:[UIFont systemFontOfSize:13.0f] constrainedToSize:CGSizeMake(230, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; cell.title.frame = CGRectMake(0, 0, size1.width, size1.height); CGSize size2 = [[mainEventTimeArray objectAtIndex:[indexPath row]] sizeWithFont:[UIFont systemFontOfSize:11.0f] constrainedToSize:CGSizeMake(230, MAXFLOAT) lineBreakMode:UILineBreakModeWordWrap]; cell.dataTime.frame = CGRectMake(0, 0, size2.width, size2.height);
user1174864
source share