我已经使用plist创建了扩展tableview,我已经将所有值和图像填充到了我的tableview中。在这里,我想为用户单击该单元格时为特定单元格制作动画。如何为我的tableviewcell图像单独创建一个动画?
例如,第一次图像将默认,下次如果我单击该单元格,特定单元格将被展开。在这里我需要让自己的形象隐藏起来;再次如果用户按它将显示图像。这个怎么做?
我已经使用plist创建了扩展tableview,我已经将所有值和图像填充到了我的tableview中。在这里,我想为用户单击该单元格时为特定单元格制作动画。如何为我的tableviewcell图像单独创建一个动画?
例如,第一次图像将默认,下次如果我单击该单元格,特定单元格将被展开。在这里我需要让自己的形象隐藏起来;再次如果用户按它将显示图像。这个怎么做?
http://www.iostute.com/2015/04/expandable-and-collapsable-tableview.html
您可以参阅本教程。这是一个基于可扩展tableview单元的非常好的教程。
这可能是非常有帮助的,但在这里不鼓励链接的答案,因为它们经常中断。它们可以提供,但也许作为本身答案的附录。 – halfer
尽管此链接可能回答此问题,但最好在此处包含答案的重要部分,并提供供参考的链接。如果链接页面更改,则仅链接答案可能会失效。 - [来自评论](/ review/low-quality-posts/16826053) –
您可以检查我的完整的解决方案在以下github
下面是我的一些实施。
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
movies = [[NSArray alloc] initWithObjects:
(NSArray*)[[Section alloc ] init:@"Istanbul" movieNames:@[@"Uskudar", @"Sariyer"] isExpanded:false],
(NSArray*)[[Section alloc ] init:@"Bursa" movieNames:@[@"Osmangazi", @"Mudanya", @"Nilufer"]
isExpanded:false],
(NSArray*)[[Section alloc ] init:@"Antalya" movieNames:@[@"Alanya", @"Kas"] isExpanded:false], nil
];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return movies.count;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return ((Section*)movies[section]).movies.count ;
}
-(void)toggleSection:(ExpandableHeaderFoorterView *)headerView withSection:(int)section
{
((Section*)movies[section]).expanded = !((Section*)movies[section]).expanded;
[expandableTableView beginUpdates];
for (int i= 0; i< ((Section*)movies[section]).movies.count; i++)
{
NSArray* rowsToReload = [NSArray arrayWithObjects:[NSIndexPath indexPathForRow:i inSection:section], nil];
[expandableTableView reloadRowsAtIndexPaths:rowsToReload
withRowAnimation:UITableViewRowAnimationFade];
}
[expandableTableView endUpdates];
}
-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
ExpandableHeaderFoorterView* headerView = [[ExpandableHeaderFoorterView alloc] initWithCustom:((Section*)movies[section]).genre withSection:(int)section withDelegate:self];
return (ExpandableHeaderFoorterView*)headerView;
}
每当用户点击一个细胞,UITableViewDelegate
方法被调用,并在此方法可以重新装载电池:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
当细胞被重新加载,下面的方法被调用(其他人之间),以及你所要做的唯一事情是与电池的当前状态,根据返回不同的高度:
- (CGFloat)tableView:(UITableView *)tableView
heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return (/* cell state */) ? 100.0 : 50.0;
}
你有多种方式来存储您的单元的状态,例如,您可以在模型中执行此操作。
还有其他方法,这只是一个解决方案。但关键是您必须重新加载单元格,并根据您要考虑的条件返回不同的高度。
你的意思是你想切换图像视图的显示? –
是的..随着闪烁的动画一起眨眼 –