我必须将IndexPath值获取到NSMutableArray。我必须在选择特定单元格时执行操作,它的IndexPath存储在NSMutableArray中,并且特定单元格高度正在增加。当我再次按下那个细胞时,特定的细胞高度正在减少。怎么可能和我必须放置什么类型的条件?
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"%@",indexPath);
selectIndexPathCell = indexPath;
NSIndexPath *previousSelectedIndexPath = selectIndexPathCell;
selectIndexPathCell = indexPath;
if (previousSelectedIndexPath) {
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:previousSelectedIndexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
}
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:selectIndexPathCell]
withRowAnimation:UITableViewRowAnimationAutomatic];
self.selectedRow = sections_main[indexPath.section][@"content"][indexPath.row];
[tblPeople beginUpdates];
[tblPeople endUpdates];
}
- (CGFloat)tableView:(UITableView *)aTableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectIndexPathCell != nil && [selectIndexPathCell compare:indexPath] == NSOrderedSame){
return 80;
}else{
return 60.0;
}
}
答案 0 :(得分:2)
据我所知,您需要基于标准的表格视图单元格高度。您可以通过在rowIndex
中保留相应单元格的array
来管理它,并且可以使用reloadData
代理在heightForRowAtIndexPath
委托下管理- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(![arrayOfExpandedCellIndexes containsObject:[NSNumber numberWithInteger:indexPath.row]])
{
[arrayOfExpandedCellIndexes addObject:[NSNumber numberWithInteger:indexPath.row]]; // add if it does not exist
}
else
{
[arrayOfExpandedCellIndexes removeObject:[NSNumber numberWithInteger:indexPath.row]]; // remove if it exists
}
[tableView reloadData]; // reload data so height would adjust in `heightForRowAtIndexPath`
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if([arrayOfExpandedCellIndexes containsObject:[NSNumber numberWithInteger:indexPath.row]])
return EXTENDED_CELL_HEIGHT; // Macro : #define EXTENDED_CELL_HEIGHT 230.0f
else
return NORMAL_CELL_HEIGHT; // Macro : #define NORMAL_CELL_HEIGHT 100.0f
}
函数高度,单元格高度将根据数组值。看看我的建议here。
希望它有所帮助!
编辑:(未经测试的版本可以提供您的想法)
arrayOfExpandedCellIndexes
假设NSMutableArray
是{{1}}来保持指标。
答案 1 :(得分:0)
Take a global variable ex: Int selectedIndex; and now in didselectrow write this
-(void)viewDidLoad
{
[super viewDidLoad];
selectedIndex=50; // please assign it as your arraycount+1; which you are using to display on tableview
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedIndex==indexPath.row)
{
// if this is true you can do decrease your cell height
selectedIndex=50; // please assign it as your arraycount+1;
}
else
{
// user can select one row and he can select another row without minimizing the previous one so you need to minimize the previous and increase new one. by using selectedIndex decrease cell height and by using indexPath.row increase height of cell
selectedIndex=indexPath.row;
}
[tableview reload];
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(selectedIndex==indexPath.row)
{
return 60;
}
else
{
return 30;
}
}