theShay
theShay

Reputation: 247

Set Width of cell by number of lines in it

i have a cell and a NSIntger that counting number of lines in string. example:

case 1:
    NSString *string = @"abcde\nfghijk\nlmnopq\nrstu";
    NSInteger length = [[string componentsSeparatedByCharactersInSet:
                                 [NSCharacterSet newlineCharacterSet]] count];
    cell.detailTextLabel.text = [NSString stringWithFormat:string];
    cell.detailTextLabel.numberOfLines = length;
    break;

this code is in - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.

how i can set the cells width by NSIntger length?

Upvotes: 0

Views: 85

Answers (1)

Abhishek
Abhishek

Reputation: 2253

If you want to sell the cell height then you have a method call back method of UITableView delegate ...

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
   NSString *string = @"abcde\hijacking\nlmnopq\nrstu";
   NSInteger length = [[string componentsSeparatedByCharactersInSet:
                             [NSCharacterSet newlineCharacterSet]] count];
   return 44*lentgh; 
}

may this will help you.

Upvotes: 1

Related Questions