我想有相同的行为Twitter的应用程序选择鸣叫那就是当:扩大该行并添加补充内容。IOS - 展开表视图细胞像Twitter的应用程序
所以这不仅是一个基本的行大小调整。我想我需要2个不同的定制单元,所以我做了这样的事情:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([indexPath compare:self.selectedIndexPath] != NSOrderedSame) {
FirstCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FirstCell"];
if (!cell) {
cell = [[FirstCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"FirstCell"];
}
cell.firstnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"firstname"];
return cell;
}
else {
SecondCell *cell = [tableView dequeueReusableCellWithIdentifier:@"SecondCell"];
if (!cell) {
cell = [[SecondCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SecondCell"];
}
cell.firstnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"firstname"];
cell.lastnameLabel.text = [[self.items objectAtIndex:indexPath.row] objectForKey:@"lastname"];
return cell;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([indexPath compare:self.selectedIndexPath] == NSOrderedSame) {
return 80.0;
} else {
return 44.0;
}
}
#pragma mark - Table view delegate
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
self.selectedIndexPath = indexPath;
[tableView reloadData];
}
我在这里的问题是,我想保持像Twitter的应用程序的流体动画这不是我的情况,因为[tableView reloadData]
(这是强制性的我认为,因为我有2个不同的自定义单元格)。
因此,任何人知道的解决方法,我需要或也许有人知道Twitter的应用程序是如何处理这个动画的东西?
这里的问题是,当我选择了某一行,其他的人都保持'SecondCell'类,因为它们没有重新加载(只有细胞体积变化)。这就是为什么我调用'[tableView reloadData]'。但是如果我用'beginUpdates/endUpdates'包围'[tableView reloadData]',那么根本就没有动画。任何解决方案? – Yaman 2013-02-19 21:38:43
嗯,是否有可能拥有相同类型的单元格并对高度和布局进行一些动态计算?我前一段时间写过这篇文章:http://www.roostersoftstudios.com/2011/04/14/iphone-uitableview-with-animated-expanding-cells/ – rooster117 2013-02-19 21:41:24
其实我在发布之前看过你的博客,但这并不完全是我想这样做,因为您只是根据文本重新调整标签大小,然后根据标签大小调整单元格大小。但在我的情况下,我想添加一些UIButton,UIImageView等,这就是为什么我认为需要2个自定义单元格。 – Yaman 2013-02-19 21:47:23