star lord
star lord

Reputation: 66

Expanding a table cell on clicking a button outside it in objective c

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    [tableView beginUpdates]; // tell the table you're about to start making changes

    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
       self.expandedIndexPath = nil;
    } else {
       self.expandedIndexPath = indexPath;
    }


[tableView endUpdates]; // tell the table you're done making your changes

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) {
       return 200.0; // Expanded height
   }
   return 44.0; // Normal height

}

- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index
{
  This is a function of getting the index , when clicking a pie chart.
  what i need to do is expand the corresponding row of table when pie is    selected
}

@end

Upvotes: 1

Views: 639

Answers (1)

Nazir
Nazir

Reputation: 1975

If i got your idea you need to select the row at index path

- (void)pieChart:(XYPieChart *)pieChart didSelectSliceAtIndex:(NSUInteger)index
{
    // get indexPath with index
    // remember if you have few sections then you will need to update inSection:0 value
    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:index inSection:0];

   [yourTableView selectRowAtIndexPath:indexPath 
                               animated:NO 
                         scrollPosition:UITableViewScrollPositionNone];

    // This will also Highlighted the row. Then delegate
    [yourTableView.delegate someTableView didSelectRowAtIndexPath:indexPath];
}

Upvotes: 1

Related Questions