ios - 在 objective-c 中单击表格单元格外部的按钮时展开表格单元格

标签 ios objective-c uitableview

- (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

最佳答案

如果我明白你的想法,你需要选择索引路径中的行

- (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];
}

关于ios - 在 objective-c 中单击表格单元格外部的按钮时展开表格单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41235711/

相关文章:

ios - 如何在 ios 中绘制具有角度和距离的线

ios - 如何搜索 PFObject UITableView

ios - 如何理解 table.autoresizingMask 的行为?

ios - 从 SpriteKit 中的类播放音频

ios - 获取格式为 UTC+5 :30 的时区

objective-c - Objective-C : How to check for unread messages (number to be displayed as badge)

iphone - 将 NSarray 项插入指定的 UItableviewcell

ios - 具有自定义 UITextView 单元格的 TableView 将导航栏滚动到屏幕外

ios - 没有调用目标为 nil 的 UIButton 函数?

iphone - Objective-C中的静态变量和多个线程