ios - Give section index without any section in table view in objective C for sorting single NSArray? -
means want records nsarray starts 'j' when tapped on 'j' section title in right side.
below give code in code don't want section have 1 plist in store states in india don't want section , when tap on alphabet @ time sorting perform , rows starts tapped alphabet want. give example above , code below
-(nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { nslog(@"enter in numberofrowsinsection method."); nslog(@"returning number of rows in plist.==%d ",test.count); return test.count; } - (uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { nslog(@"enter cellforrowatindexpath method."); nslog(@"creating cell.."); //create cell uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell"]; //the above line used reuse memory in tableview allocate memory displayed @ time. if(cell == nil){ cell = [[uitableviewcell alloc] initwithstyle:uitableviewcellstyledefault reuseidentifier:@"cell"]; } nslog(@"filling cell content.."); //fill contents cell.textlabel.text = [test objectatindex:indexpath.row]; nslog(@"cell content === %@",cell.textlabel.text); nslog(@"exit cellforrowatindexpath method."); //return return cell; } - (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview { nsarray *sectitle = [[nsarray alloc]initwithobjects:@"a", @"b",@"c",@"d",@"e",@"f",@"g",@"h",@"i",@"j", @"k",@"l",@"m",@"n",@"o",@"p",@"q",@"r",@"s", @"t",@"u",@"v",@"w",@"x",@"y",@"z", nil]; return sectitle; } - (void)viewdidload { [super viewdidload]; nslog(@"in viewdidload method"); //load plist file. nsstring *str = [[nsbundle mainbundle] pathforresource:@"groupedtest" oftype:@"plist"]; nsdictionary *dict = [[nsdictionary alloc] initwithcontentsoffile:str]; nslog(@"dict === %@",dict); test = [[nsarray alloc]initwitharray:[dict objectforkey:@"statesofindia"]]; //nslog(@"in viewdidload method & array fill plist"); nslog(@"array count(length) starts 1 not 0 = %d",test.count); nslog(@"exit viewdidload method.."); // additional setup after loading view, typically nib. }
in test nsarray declared in .h file. , please tell me answer because start learning before 5 days i'm totally new in iphone , objective c. thank much!!
there option in uitableview use case, implement uitableviewdatasource delegate methods -sectionindextitlesfortableview:
, -tableview:sectionforsectionindextitle:atindex:
for customising section titles , supporting localisation, uilocalizedindexedcollation need used. can read here
- (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview { return [[uilocalizedindexedcollation currentcollation] sectionindextitles]; } - (nsinteger)tableview:(uitableview *)tableview sectionforsectionindextitle:(nsstring *)title atindex:(nsinteger)index { return [[uilocalizedindexedcollation currentcollation] sectionforsectionindextitleatindex:index]; }
you need implement below method handle user touch on section title
- (nsinteger)tableview:(uitableview *)tableview sectionforsectionindextitle:(nsstring *)title atindex:(nsinteger)index { return [sectitle indexofobject:title]; }
Comments
Post a Comment