如何扩展我的 table 视图单元格?
How to expand my table view cell?
使用此代码扩展 table 视图单元格,但它不适用于 me.I 知道此代码中有问题,请帮助我找出答案。
![selectindex = -1;
// Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return \[Arr_lbl count\];
}
#pragma mark table cell creating and loading the data
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AntzclubCell *cell=\[tableView dequeueReusableCellWithIdentifier:@"Antz"\];
cell.img_antzClub.image=\[UIImage imageNamed:\[Arr_img objectAtIndex:indexPath.row\]\];
cell.lbl_antzClub.text=\[Arr_lbl objectAtIndex:indexPath.row\];
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor=\[UIColor blackColor\];
return cell;
}
#pragma mark expanding height
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectindex==indexPath.row){
return 400;
}
else{
return 132;
}
}
#pragma mark user selecting option
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==selectindex) {
selectindex=-1;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
return;
}
if(selectindex !=-1)
{
NSIndexPath *prepath=\[NSIndexPath indexPathForRow:selectindex inSection:0\];
selectindex=indexPath.row;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:prepath\] withRowAnimation:UITableViewRowAnimationLeft\];
}
selectindex=indexPath.row;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
}]
此图像是我单击单元格时的输出,它与其他未展开的数据合并。
根据您要支持的 iOS 版本,答案可能会有所不同,但您似乎没有实施 heightForRowAtIndexPath:
使用此代码扩展 table 视图单元格,但它不适用于 me.I 知道此代码中有问题,请帮助我找出答案。
![selectindex = -1;
// Do any additional setup after loading the view.
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return \[Arr_lbl count\];
}
#pragma mark table cell creating and loading the data
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
AntzclubCell *cell=\[tableView dequeueReusableCellWithIdentifier:@"Antz"\];
cell.img_antzClub.image=\[UIImage imageNamed:\[Arr_img objectAtIndex:indexPath.row\]\];
cell.lbl_antzClub.text=\[Arr_lbl objectAtIndex:indexPath.row\];
cell.accessoryType=UITableViewCellAccessoryDetailDisclosureButton;
cell.backgroundColor=\[UIColor blackColor\];
return cell;
}
#pragma mark expanding height
-(CGFloat)tableView:(UITableView *)tableView estimatedHeightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectindex==indexPath.row){
return 400;
}
else{
return 132;
}
}
#pragma mark user selecting option
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row==selectindex) {
selectindex=-1;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
return;
}
if(selectindex !=-1)
{
NSIndexPath *prepath=\[NSIndexPath indexPathForRow:selectindex inSection:0\];
selectindex=indexPath.row;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:prepath\] withRowAnimation:UITableViewRowAnimationLeft\];
}
selectindex=indexPath.row;
\[tableView reloadRowsAtIndexPaths:\[NSArray arrayWithObject:indexPath\] withRowAnimation:UITableViewRowAnimationFade\];
}]
根据您要支持的 iOS 版本,答案可能会有所不同,但您似乎没有实施 heightForRowAtIndexPath: