0

单击它时如何使我的单元格变大?

这是我当前不起作用的代码。

    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [feedsTableView dequeueReusableCellWithIdentifier:@"MyIdentifier"];
    static NSString *CellIdentifier = @"Cell";
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] ;

    ell.frame = CGRectMake(cell.frame.origin.x, cell.frame.origin.y, 320.0, 250.0);
    NSLog(@"[CELL CLICK] %i", indexPath.row);

    [feedsTableView beginUpdates];
    [feedsTableView endUpdates];

    [feedsTableView deselectRowAtIndexPath:indexPath animated:YES];
}
4

1 回答 1

2

你可以这样做:

NSIndexPath *selectedIndex;

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
  if (indexPath == selectedIndex)
    return 80.0f;
  else
    return 50.0f;
}

然后在 didSelectRowAtIndex 中设置 selectedIndex 变量并像这样重新加载 tableview:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
  selectedIndex = indexPath;
  [tableView reloadRowsAtIndexPaths:indexPath withRowAnimation:UITableViewRowAnimationMiddle];
}
于 2013-07-01T23:07:05.607 回答