uitableview - iOS: How can i display the section content in Grouped Table View? -


i using following sample code have section contents in "grouped table view". showing contents in "grouped table view" fine. but, issue is, sorts section content based on alphabetical order, order of section header content not displaying expected. example: want "about" shown @ end of section in tableview, here shows first (because of alphabetical sort there). how can display section content based on below code without alphabetical sorting. please advise!

    - (void)viewdidload     {         [super viewdidload];          nsarray *arrtemp4 = [[nsarray alloc]initwithobjects:@"quick logon",@"stay logged on", nil];         nsarray *arrtemp3 = [[nsarray alloc]initwithobjects:@"notifications",@"text messaging",@"family members",@"social media",nil];         nsarray *arrtemp2 = [[nsarray alloc]initwithobjects:@"payment accounts",nil];         nsarray *arrtemp1 = [[nsarray alloc]initwithobjects:@"phone nickname",@"version",nil];          nsdictionary *temp = [[nsdictionary alloc]initwithobjectsandkeys: arrtemp1,@"about", arrtemp2,@"payment preferences", arrtemp3,@"profile & preferences", arrtemp4,@"security ",  nil];          self.tablecontents = temp;          nslog(@"table %@",self.tablecontents);         nslog(@"table keys %@",[self.tablecontents allkeys]);  self.sortedkeys = [[self.tablecontents allkeys] sortedarrayusingselector:@selector(compare:)];           nslog(@"sorted %@",self.sortedkeys);      }  - (nsinteger)numberofsectionsintableview:(uitableview *)tableview{     return [self.sortedkeys count]; }  - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section {     return [self.sortedkeys objectatindex:section]; }  - (nsinteger)tableview:(uitableview *)table numberofrowsinsection:(nsinteger)section {     nsarray *listdata =[self.tablecontents objectforkey:[self.sortedkeys objectatindex:section]];     return [listdata count]; }   - (uitableviewcell *)tableview:(uitableview *)tableview          cellforrowatindexpath:(nsindexpath *)indexpath {      static nsstring *simpletableidentifier = @"simpletableidentifier";      nsarray *listdata =[self.tablecontents objectforkey:[self.sortedkeys objectatindex:[indexpath section]]];      uitableviewcell * cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier];      if(cell == nil) {          cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier];         //cell.accessorytype = uitableviewcellaccessorydisclosureindicator;      }     cell.accessorytype = indexpath.section > 0 ? uitableviewcellaccessorydisclosureindicator : uitableviewcellaccessorynone;      nsuinteger row = [indexpath row];     cell.textlabel.text = [listdata objectatindex:row];      nslog(@"indexpath.section %d",indexpath.section);       if ( indexpath.section==0 )     {        // cell.imageview.image = [uiimage imagenamed:@"icon.png"];     }     //cell.switch.hidden = indexpath.section > 0;      return cell; } 

thanks in advance!

don't use sortedarrayusingselector:. instead, explicitly create key array in order want. then, create tablecontents using key array , array created hold of content arrays (using dictionarywithobjects:forkeys:).

nsarray *keys = @[ @"about", @"payment preferences", @"profile & preferences", @"security" ]; nsarray *values = @[ arrtemp1, arrtemp2, arrtemp3, arrtemp4 ];  self.tablecontents = [nsdictionary dictionarywithobjects:values forkeys:keys]; self.sortedkeys = keys; 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -