Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to animate table view cells when switching between buttons of UISegmentedControl?
    primarykey
    data
    text
    <p>My application is looking like the below image</p> <p><img src="https://i.stack.imgur.com/yTitp.png" alt="enter image description here"> <img src="https://i.stack.imgur.com/hDIgd.png" alt="enter image description here"></p> <p>I have 3 buttons in my segmented control. Assume that hitting the "Department" button will display 3 departments &amp; hitting "Name" button will show 6 names.</p> <p>I follow the below steps to make this..</p> <ol> <li><p>Create UISegmentedControl by this code</p> <pre><code>segmentedControl = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Department", @"Name", @"ID",nil]]; //Initialize Segmented Control segmentedControl.segmentedControlStyle = UISegmentedControlStyleBar; //Define bar type (optional) segmentedControl.selectedSegmentIndex = 0; //Define default clicked button [segmentedControl addTarget:self action:@selector(segmentClicked) forControlEvents:UIControlEventValueChanged]; //Set target and define which method should called when tapping buttons self.navigationItem.titleView = segmentedControl; //To add UISegmented Control in the title of the navigation bar </code></pre></li> <li><p>Define the method(<code>segmentClicked</code>) for UISegmented Control</p> <pre><code>segment = segmentedControl.selectedSegmentIndex; if (segment==0) { //Do something for Department tab [self.tableView reloadData]; } else if (segment==1) { //Do something for Name tab [self.tableView reloadData]; } else { //Do something for ID tab [self.tableView reloadData]; } </code></pre></li> <li><p>Create the cells with reference to the value of segment in <code>tableView: cellForRowAtIndexPath:</code> method. (So that we can get various cells for each UISegmentedControl buttons)</p> <pre><code>if (segment == 0) { cell.textLabel.text = [listOfDepartments objectAtIndex:indexPath.section]; //listOfDepartments is the NSMutableArray that contains list of Departments names } else if (segment == 1) { cell.textLabel.text = [listOfNames objectAtIndex:indexPath.section]; //listOfNames is the NSMutableArray that contains list of person names } else { cell.textLabel.text = [listOfIDs objectAtIndex:indexPath.section]; //listOfIDs is the NSMutableArray that contains list of person ID's } return cell; </code></pre></li> </ol> <p>So, finally i got the view showed in the above image.</p> <p>When i press on the UISegmentedControl buttons, the table view reloads its cells &amp; showing corresponding values perfectly. By default, the "Department" button was selected. If i tap the "Name" button(that is, table will show 6 cells instead of 3), The table changes immediately without any animations. It simply hide 3 cells of department names and showing 6 cells that displaying names of persons without any animations. I could not find a way to making the cell changes with smooth animations. </p> <p>What should i implement to achieve the smooth animations? </p> <p>Thanks in Advance</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload