简体   繁体   中英

Displaying new data under selected row in a table view

I have a table view on the screen which has five rows when the view is opened.

When we select the row, new rows will added below the selected row (new rows = array count from other view).

When we select the row again, it has to display 5 rows again. Like that in my table view when we select the row some rows will be added based on array count. Again I click the same row it has to display 5 rows again. How can I do that?

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{
     return currentrows;
}

if(selectedIndex == 0)
{   
     for (int j=1;j<=[passionarray count];j++) 
     {
          currentrows = currentrows + 1;
          NSLog(@"numberofrowsatindex %d",currentrows);
          NSIndexPath *indexPath1 = [NSIndexPath indexPathForRow:j inSection:0];

          [tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath1, nil] withRowAnimation:UITableViewRowAnimationFade];
          selected=YES;
     }

Are you reloading the table and forcing it to go through its data source again to refresh the actual view? It may already be elsewhere in your code that we cannot see, but after augmenting your data source to reflect the new row count, call [tableView reloadData];

Good Luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM