ios – 展开表格视图单元格像Twitter应用程序
在select推文时,我想要与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个不同的自定义单元格)的stream体animation。
所以任何人都知道我需要的解决方法,或者有人知道Twitter应用程序如何处理这个animation的东西?
你想用animation重新加载该单元格:
[tableView beginUpdates]; [tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; [tableView endUpdates];
[tableView beginUpdates]; [tableView endUpdates];
这会触发整个tableView的单元格行大小的更新。引用来自: iPhone – 用于UITableViewCell高度更改的平滑animation,包括内容更新
快乐编码!
实际上,使用两个自定义单元来实现这一点非常简单,就像您最初想要的,只需将您的原始代码与rooster117的解决scheme相结合即可。 用你的tableView:didSelectRowAtIndexPath:
replace[tableView reloadData]
:
[tableView beginUpdates]; [tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; [tableView endUpdates];
你应该有你的解决scheme。
- 在iOS4 +中显式禁用UIViewanimation
- 如何做IOS翻转贺卡
- 在Swift中逐行淡入UITableViewCell
- 如何检测由CATransaction触发的animation的完成?
- 当有很多使用阴影的UILabels运行的UIViewanimation时,设备会冻结,然后按Homebutton
- 核心animationCALayer掩盖animationperformance
- iOS的GoogleMaps SDK – animateToCameraPositionanimation完成处理程序?
- animationUIButton背景图像
- 在iOS上使用resizableImages时避免混合图层