I want to expand a cell in my table view when I select it. Initially it should look like this:
And on expanding, it should give more detail like this:
This is how I'm creating the cell initially:
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString * MyIdentifier = @"MyIdentifier";
UITableViewCell * cell = [self.table dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:MyIdentifier] autorelease];
cell.textLabel.frame = CGRectMake(0, 0, cell.textLabel.frame.size.width,
cell.textLabel.frame.size.height);
}
id key = [[articles allKeys] objectAtIndex:indexPath.section];
cell.textLabel.text =@"TitleTitleTitle";
cell.detailTextLabel.text=@"DeatailDeatailDeatailDeatailDeatailDeatailDeatailDeatailDeatai";
return cell;
}
I published a sample code at github
Your
tabelView:cellForRowAtIndexPath:
could look like this.BUT
You will also need the height of the cell by dynamic in
tableView:heightForRowAtIndexPath:
, so you should refactor the sizing parts into a helper methods, that writes the sizes of the 2 labels and the height of the cell to ivars, call the method fromtableView:heightForRowAtIndexPath:
, use the cell height there and the labels sizes intabelView:cellForRowAtIndexPath: