如何在UITableView中创建行的扩展和折叠,
我按照了这个视频,“https://www.youtube.com/watch?v=OYaI5ASpsOE”点击了单元格后出现了以下错误。
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unable to compare <NSIndexPath: 0x600000029560> {length = 2, path = 0 - 18446744073709551615} with object of different class: NSArray'
答案 0 :(得分:0)
请使用This库。只需使用POD将其添加到您的项目中。
pod 'ExpandableCell'
将其导入您的viewController
import ExpandableCell
在Storyboard或代码中创建ExpandableTableView
@IBOutlet var tableView: ExpandableTableView!
继承ExpandableDelegate
class ViewController: UIViewController, ExpandableDelegate
设置代理
tableView.expandableDelegate = self
答案 1 :(得分:0)
下面的tableview委托和数据源代码我使用崩溃是不可复制的
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.arrowtitle.count;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
ExpandingCell *cell = (ExpandingCell *)[tableView dequeueReusableCellWithIdentifier:CELL_IDENTIFIER forIndexPath:indexPath];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle]loadNibNamed:@"Expanding Cell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
cell.lblrow.text = self.arrow[indexPath.row];
cell.lblrowtitle.text = self.arrowtitle[indexPath.row];
cell.lblfruit.text = self.arrFruit[indexPath.row];
NSInteger cal = (indexPath.row) * 25;
cell.lblcalcal.text = [NSString stringWithFormat:@"%ld",(long) cal];
return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return (self.selectedIndex == indexPath.row) ? 120 : 45 ;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (self.selectedIndex == indexPath.row) {
self.selectedIndex = -1;
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
return;
}
if (self.selectedIndex == -1) {
NSIndexPath *prev = [NSIndexPath indexPathForRow:self.selectedIndex inSection:0];
self.selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:@[prev] withRowAnimation:UITableViewRowAnimationFade];
}
self.selectedIndex = indexPath.row;
[tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}