views:

254

answers:

2

i m trying to read some RSS data. I have the data that is of different sizes. the data is present in tabke view data object. I used the label to add the data and resize the dat. No success. Please help.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";
 NSLog(@"in the tabel view cell");
    heightOfCell=[self tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Default"];
    if (cell == nil) {


        //cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(55.0,42.0,245.0,heightOfCell) reuseIdentifier:@"Default"] autorelease];
  UILabel *label = [[UILabel alloc] init];
  NSString *cellText = [[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]];
  UIFont *cellFont = [UIFont fontWithName:@"Helvetica" size:10.0];
  CGSize constraintSize = CGSizeMake(280.0f, MAXFLOAT);
  label.text = [[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]];
  CGSize labelSize = [[[TableViewData news] valueForKey:[NSString stringWithFormat:@"%d",[indexPath row]]] sizeWithFont:cellFont constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];



  label.lineBreakMode=UILineBreakModeWordWrap;
  [label sizeThatFits:labelSize];
  cell = [[[UITableViewCell alloc] initWithFrame:CGRectMake(55.0,42.0,245.0,heightOfCell) reuseIdentifier:@"Default"] autorelease];
  //[label sizeToFit];
  [cell addSubview:label];
  [label release];

}
A: 

You need to implement the following method:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    }
ennuikiller
A: 

You have to know the heights of all cells before the tableView:cellForRowAtIndexPath: delegate call which may require you to store heights inside your view controller or some other list.

The function to customise the heights of cells is tableView:heightForRowAtIndexPath:. The default height for a table view is 44 pixels, for reference.

You can find the documentation here.

Nick Bedford