0

It's My first time to post a question, thank you for you all in advanced.

Now, i want to implement a default style grouped UITableView contains multiple group of data. for each row, there will be a detail Disclosure button as accessoryType icon. when people click on the disclosure button, i want the Cell expand with detail info for the selected row.

i was trying to fulfill this task by add a customized cell to selected row, however, it was very complex. So currently, i am trying to finish this task by reload a specific row with Customized cell xib. i knew there is a delegate method for reloadRowsAtIndexPaths. but can i use this to reload a specific cell? Thanks

please suggest!

Great Thanks

Magnus
  • 173
  • 2
  • 7

2 Answers2

0

Have you tried something like this:

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
   if(indexPath.row == mySpecialSelectedCell)
   {
      //Load all your custom stuff here
   }
   else
   {
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
   }
   if (cell == nil) 
   {

   }

   return cell;
}

You would have to get the cell's indexPath when you click the expand button.

Or you could look at this answer. And then, like the code above, just load that one cell that you have specified with that NIB and load the rest the way you would normally.

Community
  • 1
  • 1
Putz1103
  • 6,211
  • 1
  • 18
  • 25
  • Thank you for your reply! the problem for your solution is that, how to distinguish which row is default and which row is expanded. i mean, for example, i have 5 row for first group, then i expand the first row, so, the 2nd row will become customized row. so it's impossible to figure out which is default cell and which is customized cell. :( – Magnus Jan 31 '13 at 16:11
  • Also, when we add new row, it will also call cellForRowAtIndexPath: and go through if(cell == nil), how to distinguish if this is for init the default cell or this is for customized cell? Thanks – Magnus Jan 31 '13 at 16:13
  • 1
    You need to create a class variable that contains the currently selected cell indexPath. Then when you get `didSelectCellAtIndexPath` you set that variable to the indexpath selected and reload the table data. Then you always no the selected cell and can then create the custom view based on the selection. – Putz1103 Jan 31 '13 at 16:26
0

You can implement the tableview delegate methods to set the height for the cell which needs to expand. Add some condition check in heightForRow method and when user taps on button, change the condition to increase the height. When table is reloading it will call this method and will reload cell with bigger height.

  • Hi, i checked, we cannot hide elements by reduce the height of cells, elements will overlap to each other, thanks anyway – Magnus Jan 31 '13 at 21:30