Ios 如何在UITableView中创建行的展开和折叠
如何在UITableView中创建行的展开和折叠 我看了这段视频,“点击手机后,我发现以下错误Ios 如何在UITableView中创建行的展开和折叠,ios,objective-c,uitableview,Ios,Objective C,Uitableview,如何在UITableView中创建行的展开和折叠 我看了这段视频,“点击手机后,我发现以下错误 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法将{length=2,path=0-18446744073709551615}与不同类的对象进行比较:NSArray”请使用库。只需使用POD将其添加到您的项目中 pod 'ExpandableCell' 将其导入到viewController中 import ExpandableCell 在情节提
由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“无法将{length=2,path=0-18446744073709551615}与不同类的对象进行比较:NSArray”
请使用库。只需使用POD将其添加到您的项目中
pod 'ExpandableCell'
将其导入到viewController中
import ExpandableCell
在情节提要或代码中创建可扩展的TableView
@IBOutlet var tableView: ExpandableTableView!
继承可扩展委托
class ViewController: UIViewController, ExpandableDelegate
集合委托
tableView.expandableDelegate = self
参考:在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];
}
问题是在Obj c中提出的而不是SWIFT此库位于目标c上,请在评论中的答案y中发布?请检查它是否对您有效,然后我将添加它作为答案。这是最好的链接之一尝试此。。。。