Faced such a problem. with long text, the program should otomatically spend the night on the line below. It seems that everything is written correctly, and the speed of the "0" is different, but it does not do everything that is necessary. Help pliz!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath int elementNumber = [indexPath section]; static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier"; UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier]; if(cell == nil) { cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease]; } SMXMLElement *elem = [[self.globalArray objectAtIndex:indexPath.section] objectAtIndex:0]; NSString* tmpStr = [elem attributeNamed:@"text"]; NSString* tmpStrT = [elem attributeNamed:@"author"]; NSArray *children = [NSArray arrayWithObjects:tmpStr, tmpStrT, nil]; cell.textLabel.text = [children objectAtIndex:0]; cell.detailTextLabel.text = [children objectAtIndex:1]; return cell; } - (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath: (NSIndexPath *) indexPath { int elementNumber = [indexPath section]; SMXMLElement *elem=[[self.globalArray objectAtIndex:indexPath.section] objectAtIndex:0]; NSString *str = [elem attributeNamed:@"text"]; UILabel *longi = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 280, 0)]; longi.numberOfLines = 0; longi.text = str; [longi sizeToFit]; float i = longi.frame.size.height; [longi release]; return i; } 
  • And what exactly should your transfer in your code? What I see: - you create an inscription in the function that returns the cell size (why - it is not clear, I already wrote to you several times about the corresponding NSString methods), but immediately destroy it, and if you did not destroy it - you would not see it on the screen did not add -You assign the string textLabel, but you didn’t make the number of lines and did not pull sizeToFit, why would it change? Separate idiocy to pull the lines out of the dictionary, insert them into the array and immediately pull them out of the array and assign them yet why? - aknew
  • NSString displays incorrectly! He has glitches and my, damn program, falls under this trouble! I create a Label with a zadonym in length. what would he do the transfer in the right place for me. I say that there are unlimited lines. I add a text with a label (it is now getting out of the box) Then I make a match with the size of the label. Further, if it does not fit, I increase the height (here the idea should be carried over) At the same time, the value I write to the float I no longer need a longi, I clean it and return the float value! That's how I see my prog! - Svyatoslav Boyko
  • Okay, let's say, but from where does textLabel need to know that it should be adjusted, and not just trim how the caption behaves by default? - aknew
  • All the while, I had to do the numberOfLines in the cell method. and it looks like this cell.textLabel.numberOfLines = 0; Voila - Svyatoslav Boyko
  • I actually wrote this in the first comment: ** - you assign the string textLabel, but you didn't make the number of lines ** [equal to zero - unfinished] ** and did not pull sizeToFit, why would it change ** - aknew

1 answer 1

Counting cell height .

  • Thanks for the help. Here really is what we need =) - Svyatoslav Boyko