uitableview:创建一个可折叠的tableview(可用于下拉菜单)
问题描述:
我是iphone开发的新手,无法理解各种方法和所有。我想创建一个可折叠的表格视图,通过点击一个按钮来展开和折叠。uitableview:创建一个可折叠的tableview(可用于下拉菜单)
我已经按照我的拼图
1)我想我将不得不使用动画
[collapsibleTableView deleteRowsAtIndexPaths:editableIndexArray withRowAnimation:UITableViewRowAnimationTop ];
[collapsibleTableView insertRowsAtIndexPaths:editableIndexArray withRowAnimation:UITableViewRowAnimationTop ];
这两种方法,但我不知道有关的说法,我需要传递给deleteRowsAtIndexPath:
方法和insertRowsAtIndexPath:
方法。
2)我有一个数组是这个表的数据源。
如果你能让我明白它究竟需要怎样完成,那将是非常棒的。
答
得到的答案和实施
- (NSArray*)indexPathsInSection:(NSInteger)section {
NSMutableArray *paths = [NSMutableArray array];
NSInteger row;
for (row = 0; row < [self numberOfRowsInSection:section]; row++) {
[paths addObject:[NSIndexPath indexPathForRow:row inSection:section]];
}
return [NSArray arrayWithArray:paths];
}
-(NSInteger)numberOfRowsInSection:(NSInteger)section {
return 4;
}
-(IBAction)expandCollapseMenu {
NSArray *paths = [self indexPathsInSection:0];
if (isExpanded) {
isExpanded=NO;
[actionBtn setTitle:@"Expand" forState:UIControlStateNormal];
[menuTblView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
}
else {
isExpanded=YES;
[actionBtn setTitle:@"Collapse" forState:UIControlStateNormal];
[menuTblView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade ];
}
}
答
通过扩展和契约,你是否仅仅意味着删除所有条目(整个表或部分?),或者你的意思是动画从屏幕上删除/添加tableview。
如果你的意思是删除/添加行,那么你最好的选择是可能有一个数组来保存你所有真实的有效数据和一个包含“这是用户可以看到”数据的数组 - 这样你就可以在删除/添加行时清除它或其中的一部分。
要获取indexPaths,可以使用[NSIndexPath indexPathForRow:<#(NSUInteger)#> inSection:<#(NSUInteger)#>]
创建单个路径并将它们推送到传递给该方法的数组中。
只要确保在添加/删除行时保持“这是用户可以看到的”数组,那么当tableview显示单元格时,它将请求您的基础数据。
你能解释我如何使用这个正是我不知道如何使用它。 – 2011-03-31 05:35:25