iphone - Core Data sectionNameKeyPath Custom String -
when sorting table of objects core data, i'd set custom string section heading includes attribute. example, i'd section name display "4 stars", instead of 4. i've fiddle it, seems grumpy if try set string sectionnamekeypath other entity attribute , entity attribute. here's works attribute only, , 1 of few attempts customize string breaks commented out.
nssortdescriptor *ratingdescriptor = [[nssortdescriptor alloc] initwithkey:@"starrating" ascending:no]; sortdescriptors = [nsarray arraywithobjects:ratingdescriptor, namedescriptor, nil]; [ratingdescriptor release], ratingdescriptor = nil; // nsstring *starsectionheading = [nsstring stringwithformat:@"%d stars", @"starrating"]; // sectionkeypath = starsectionheading; sectionkeypath = @"starrating";
set sectionnamekeypath "starrating" modify output in table view. frc sort things , tidy things in sections have change display header string.
- (nsstring *)tableview:(uitableview *)tableview titleforheaderinsection:(nsinteger)section { // display stars section headings. int stars = [[[[fetchedresultscontroller sections] objectatindex:section] valueforkey:@"name"] intvalue]; if(stars == 1) { return @"1 star" } else { return [nsstring stringwithformat:@"%u stars", stars]; } }
i in table views output format handled in generic fashion (i delegate header titles controller class given first sort descriptor path , value of title). not limited hard coding table view delegate methods above code.
you chance localize string here well, have deal 15 localizations in app , have think things bit differently when localizing.
Comments
Post a Comment