I have been populating a UITable view cell with the data fetched from a database. The length of the data varies for different cells. So i need to expand or Contract the height depend the data length. Presently i am using a custom cell with the following code.
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellID= @"customcell4fan";
customcell4fan *cell = (customcell4fan *)[tableView dequeueReusableCellWithIdentifier:cellID];
if(cell==nil)
{
NSArray *nibObjects = [[NSBundle mainBundle] loadNibNamed:@"customcell4fan" owner:nil options:nil];
for(id currentObject in nibObjects)
{
if([currentObject isKindOfClass: [customcell4fan class]])
{
cell = (customcell4fan *)currentObject;
}
}
}
eleme = [xmlElementObjects objectAtIndex:indexPath.section];
NSString *email= [eleme.title stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \n\t"]];
NSString *postData= [eleme.description stringByTrimmingCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@" \n\t"]];
cell.nameLabel.text=email;
cell.postLabel.text=postData;
return cell;
}
try this http://www.roostersoftstudios.com/2011/04/14/iphone-uitableview-with-animated-expanding-cells/ i find it very helpful