in this example, from theElements code provided by Apple, they Sort an Array alphabetically by Name, they also provide headers for each section (i.e: a,b,c,d etc)
if i am loading directly from a sqlite3 database into a TableView how could i do the same thing, bubblesort it and arrange it in Section headers
i was thinking you could load that sqlite3 data into an array and sort the array but that doesn't seem to effiecient/as in your loading the same data twice when you already loaded it from the database
any suggestions
thanks
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
// this table has multiple sections. One for each unique character that an element begins with
// [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z]
// return the count of that array
return [[[PeriodicElements sharedPeriodicElements] elementNameIndexArray] count];
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
// returns the array of section titles. There is one entry for each unique character that an element begins with
// [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z]
return [[PeriodicElements sharedPeriodicElements] elementNameIndexArray];
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
return index;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// the section represents the initial letter of the element
// return that letter
NSString *initialLetter = [[[PeriodicElements sharedPeriodicElements] elementNameIndexArray] objectAtIndex:section];
// get the array of elements that begin with that letter
NSArray *elementsWithInitialLetter = [[PeriodicElements sharedPeriodicElements] elementsWithInitialLetter:initialLetter];
// return the count
return [elementsWithInitialLetter count];
}
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
// this table has multiple sections. One for each unique character that an element begins with
// [A,B,C,D,E,F,G,H,I,K,L,M,N,O,P,R,S,T,U,V,X,Y,Z]
// return the letter that represents the requested section
// this is actually a delegate method, but we forward the request to the datasource in the view controller
return [[[PeriodicElements sharedPeriodicElements] elementNameIndexArray] objectAtIndex:section];
}
if i am loading directly from a sqlite3 database into a TableView how could i do the same thing, bubblesort it and arrange it in Section headers
i was thinking you could load that sqlite3 data into an array and sort the array but that doesn't seem to effiecient/as in your loading the same data twice when you already loaded it from the database
any suggestions
thanks