質問

I have to get the IndexPath values to the NSMutableArray. I have to do an operation when a particular cell is selected at that time it's IndexPath is stored in NSMutableArray and particular cell height is increasing. When I am pressing again on the that cell at that time particular cell height is decreasing. How can it possible and what type of condition do I have to put?

- (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;
}

}

役に立ちましたか?

解決

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;
}

}

他のヒント

As I understood, you want criteria based table view cell height. You can manage it by keeping the corresponding cell's rowIndex in an array, and by using reloadData function heights can be managed under heightForRowAtIndexPath delegate, the cells height will be changed according to array values. Have a look at my suggestion here.

Hope it helps!

EDIT: (untested version to give you an idea)

- (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 
}

Assuming arrayOfExpandedCellIndexes is an NSMutableArray to maintain indicies.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top