ios - Indexed Table View for Facebook Friends -



ios - Indexed Table View for Facebook Friends -

i trying sort facebook friends list in order implement indexed table view, 1 found in facebook messenger.

i tried utilize uilocalizedindexedcollation stuck on "collationstringselector" because datasource array id<"fbgraphuser"> objects , hence have no properties can utilize selector. ideas of how implement (it not have using method, open anything!)?

-(nsarray *)partitionobjects:(nsarray *)array collationstringselector:(sel)selector { uilocalizedindexedcollation *collation = [uilocalizedindexedcollation currentcollation]; nsinteger sectioncount = [[collation sectiontitles] count]; // section count take sectiontitles , not sectionindextitles nsmutablearray *unsortedsections = [nsmutablearray arraywithcapacity:sectioncount]; // create array hold info each section (int = 0; < sectioncount; i++) { [unsortedsections addobject:[nsmutablearray array]]; } // set each object section (id object in array) { nsinteger index = [collation sectionforobject:object collationstringselector:selector]; [[unsortedsections objectatindex:index] addobject:object]; } nsmutablearray *sections = [nsmutablearray arraywithcapacity:sectioncount]; // sort each section (nsmutablearray *section in unsortedsections) { [sections addobject:[collation sortedarrayfromarray:section collationstringselector:selector]]; } homecoming sections; }

here subclass of uitableviewcontroller created time ago create indexed table view. utilize base of operations class controller table view appears on screen, it's intended reusable class hard work of creating table. might able utilize is, didn't seek create universal. pass in simple array of custom objects (my objects had first , lastly names), , class creates sections , index. here's code,

the .h

@interface rdindexedtablecontroller : uitableviewcontroller @property (strong,nonatomic) nsarray *inputarray; @property (strong,nonatomic) nsstring *sectionkey; @property (strong,nonatomic) nsstring *secondarysortkey; @property (nonatomic, retain) nsmutablearray *sectionsarray; @property (nonatomic, retain) uilocalizedindexedcollation *collation; -(void)convertarray:(nsarray *)input usingsectionkey:(nsstring *)key secondarysortkey:(nsstring *)sorter; @end

the .m

@interface rdindexedtablecontroller () @property (strong,nonatomic) nsmutablearray *firstletterarray; @end @implementation rdindexedtablecontroller -(void)convertarray:(nsarray *)input usingsectionkey:(nsstring *)key secondarysortkey:(nsstring *)sorter { self.inputarray = input; self.sectionkey = key; self.secondarysortkey = sorter; [self configuresections]; } - (void)configuresections { self.collation = [uilocalizedindexedcollation currentcollation]; nsinteger sectiontitlescount = [[self.collation sectiontitles] count]; nsmutablearray *newsectionsarray = [[nsmutablearray alloc] initwithcapacity:sectiontitlescount]; (int index = 0; index < sectiontitlescount; index++) { nsmutablearray *array = [[nsmutablearray alloc] init]; [newsectionsarray addobject:array]; } (id obj in self.inputarray) { nsinteger sectionnumber = [self.collation.sectiontitles indexofobject:[[obj valueforkey:self.sectionkey] substringtoindex:1]]; nsmutablearray *sectionforobjects = [newsectionsarray objectatindex:sectionnumber]; [sectionforobjects addobject:obj]; } (int index = 0; index < sectiontitlescount; index++) { nsmutablearray *objectarrayforsection = [newsectionsarray objectatindex:index]; nsarray *firstsortedobjectarrayforsection = [self.collation sortedarrayfromarray:objectarrayforsection collationstringselector:nsselectorfromstring(self.secondarysortkey)]; nsarray *sortedobjectarrayforsection = [self.collation sortedarrayfromarray:firstsortedobjectarrayforsection collationstringselector:nsselectorfromstring(self.sectionkey)]; [newsectionsarray replaceobjectatindex:index withobject:sortedobjectarrayforsection]; } self.sectionsarray = newsectionsarray; } - (nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming self.collation.sectiontitles.count; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { nsarray *objectsinsection = [self.sectionsarray objectatindex:section]; homecoming objectsinsection.count; } - (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section { homecoming self.collation.sectiontitles[section]; } -(cgfloat)tableview:(uitableview *)tableview heightforheaderinsection:(nsinteger)section { if ([[self.sectionsarray objectatindex:section] count] == 0) { homecoming 0; }else{ homecoming 30; } } - (nsarray *)sectionindextitlesfortableview:(uitableview *)tableview { homecoming @[@"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"]; } - (nsinteger)tableview:(uitableview *)tableview sectionforsectionindextitle:(nsstring *)title atindex:(nsinteger)index { homecoming [self.collation sectionforsectionindextitleatindex:index]; }

in table view controller appears in app, need little amount of code populate table,

-(void)viewdidload { [super viewdidload]; [self.tableview registerclass:[uitableviewcell class] forcellreuseidentifier:@"cell"]; nsmutablearray *mut = [nsmutablearray new]; // create person objects , add together them array here [self convertarray:mut usingsectionkey:@"lastname" secondarysortkey:@"firstname"]; [self.tableview reloaddata]; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:@"cell" forindexpath:indexpath]; nsstring *first = [self.sectionsarray[indexpath.section][indexpath.row] valueforkey:@"firstname"]; nsstring *last = [self.sectionsarray[indexpath.section][indexpath.row] valueforkey:@"lastname"]; cell.textlabel.text = [nsstring stringwithformat:@"%@ %@",first,last]; homecoming cell; }

ios objective-c uitableview facebook-graph-api

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -