UITableViewCell - 滚动停止后的子视图重新布局

时间:2013-05-30 20:19:00

标签: ios uitableview scroll

我有一个自定义的UITableViewCell,里面有一些扩展菜单。 带菜单的单元格如下所示:

+--------------+
|(>)--(a)--(b) | (cell#1 - expanded)
+--------------+
+--------------+
|(<)           | (cell#2 - not expanded)
+--------------+
> = root menu button
a = expanded item 1
b = expanded item 2

由于单元格被重复使用,我需要关闭菜单(如果它已展开),当单元格出列时,所以新出现的单元格将出现,菜单关闭。

问题是,在表格视图滚动停止之前,出列单元格中的菜单不会关闭。 有没有办法在单元格出列后立即关闭菜单?

感谢。

3 个答案:

答案 0 :(得分:0)

尝试在您的单元格中使用方法-(void)prepareForReuseHere是对它的描述。

答案 1 :(得分:0)

如果没有要分析的代码,很难说出你的问题是什么,但你可以使用cellForRow属性和isMenuOpened类似的自定义单元格在closeMenu方法中实现此问题这个

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell"; 
    YourCustomCell*cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
      cell = [[YourCustomCell alloc] initWithStyle:UITableViewCellStyleDefault
                                     reuseIdentifier:CellIdentifier];
      //perform init setup here or other ops
    }
    else { 
       if(cell.isMenuOpened) {
           [cell closeMenu];
       }
       //do other setup here, set text and other stuffs
    }

   return cell
}

xexe 建议的方法在使用轻型属性更改(例如alpha)和与内容无关的属性时可以正常运行。

答案 2 :(得分:0)

问题解决了。 我不得不使用“当前的NSRunLoop模式”:

 [self performSelector:@selector(animateItemToStartPoint:)
              withObject:dictionary
              afterDelay:animation.delayBetweenItemAnimation * x
                 inModes:@[[[NSRunLoop currentRunLoop] currentMode], NSDefaultRunLoopMode]];