ios - sectioned table view returning blank table -
ios - sectioned table view returning blank table -
i found code examples online creating tableview alphabetical sections , have tried adapt tableview.
however, simulator returning blank table.
i've gone wrong, mind pointing out mistakes? every alter create doesn't help. give thanks you
#import "rcviewcontroller.h" @interface rcviewcontroller () @end @implementation rcviewcontroller @synthesize content = _content; @synthesize sectiondata; @synthesize sectionnames; -(nsarray *)content { nsarray *words = [nsarray arraywithobjects:@"tee", @"club", @"green", @"putt", nil]; nsarray *sortedwords = [words sortedarrayusingselector:@selector(caseinsensitivecompare:)]; nsstring *currentletter = @""; (nsstring *string in sortedwords) { if (string.length>0) { nsstring *letter = [string substringtoindex:1]; if (![letter isequaltostring:currentletter]) { [sectionnames addobject:letter]; currentletter = letter; nsmutablearray *onesection = [nsmutablearray array]; [sectiondata addobject:onesection]; [[sectiondata lastobject]addobject:string]; } } } homecoming _content; } -(nsinteger)numberofsectionsintableview:(uitableview *)tableview { homecoming sectionnames.count; } - (nsinteger)tableview:(uitableview *)tableview numberofrowsinsection:(nsinteger)section { homecoming [[sectiondata objectatindex:section]count]; } -(nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section { homecoming [sectionnames objectatindex:section]; } -(nsarray *)sectionindextitlesfortableview:(uitableview *)tableview { homecoming sectionnames; } -(uitableviewcell *)tableview:(uitableview *)tableview cellforrowatindexpath:(nsindexpath *)indexpath { static nsstring *simpletableidentifier = @"simpletableidentifier"; uitableviewcell *cell = [tableview dequeuereusablecellwithidentifier:simpletableidentifier]; if (cell == nil) { cell = [[uitableviewcell alloc]initwithstyle:uitableviewcellstyledefault reuseidentifier:simpletableidentifier]; cell.textlabel.text =[[self.sectiondata objectatindex:indexpath.section]objectatindex:indexpath.row]; } homecoming cell; } - (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. } - (void)didreceivememorywarning { [super didreceivememorywarning]; // dispose of resources can recreated. } @end
there bunch of things not optimal code causing table blank never populating sectiondata , sectionname , returns table no section names or section data. seek this:
- (void)viewdidload { [super viewdidload]; // additional setup after loading view, typically nib. nsarray *words = [nsarray arraywithobjects:@"tee", @"club", @"green", @"putt", nil]; nsarray *sortedwords = [words sortedarrayusingselector:@selector(caseinsensitivecompare:)]; nsstring *currentletter = @""; (nsstring *string in sortedwords) { if (string.length>0) { nsstring *letter = [string substringtoindex:1]; if (![letter isequaltostring:currentletter]) { [sectionnames addobject:letter]; currentletter = letter; nsmutablearray *onesection = [nsmutablearray array]; [sectiondata addobject:onesection]; [[sectiondata lastobject]addobject:string]; } } } }
ios uitableview
Comments
Post a Comment