If you could find a tutorial for an indexed table view based on last name like the "Contacts" app, that would be great. I've search all around but can't find one on last names.
I guess you store your contacts using core data. You probably have a entity "Person" with attributes first name, last name, address etc.
You should make a subclass of NSManagedObject specifically for the entity "Person". In this class, you add a method that returns only the first letter of the last name. If you have a NSFetchedResultsController you can apply the path name for the sections. There you just write the name of exactly that method that returns the first letter. The table view should then be sectioned by the last name's first letter like in contacts.
Now, you should implement the method
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
You return a array that contains all the index titles which will appear on the right. Let's say if your contacts are "Steve Jobs" and "Jony Ive", there would be two sections and two index titles "I" and "J". You don't have to put all letters of the whole alphabet in the array, just those that you really need.
Related
Am having the task like in UITableView, In root view i have country list if selected the country it should navigate to next view display the state list of that country, if i select state it should navigate and displays the cities, if i select city need displays a popular areas and then hospitals list in that area how do i create plist for that. Then how shall i get value from that plist.
For this you can create PList as follows:
add independent rows for each country. Each row set value type as array. And values add multiple rows & put state and for value again put data type as Array. And put respective cities into that.
It will work for you then.
there are more ways to do it but in this case you'll get all data in a single dictionary and you can maintain your table easily using it.
I am working on a basic iPhone app that pulls restaurant objects from a SQLite table, and displays them for the user in a table. My app is navigation based. I have no problems pulling the data from the SQLite database, and then sorting them. That I am able to do no problem. Each restaurant object has various properties, like "name", "address", "category" (i.e. the type of restaurant like greek, italian), and others. Now, after retrieving the records from the database, I am able to successfully put them into an NSMutableArray, and then sort them into an NSArray.
My question is, using this NSArray (or the original NSMutableArray), I'd like to create another array, with the first index containing "All", and then each remaining index contain the unique name of the category of restaurant from the original list, sorted in alphabetical order, and then present this as a table to the user on the next screen. From this table, if the user selects "All", the user will be taken to another screen displaying another table where they can see all the restaurants, regardless of genre.
If however, the user selects a particular category from the available list, the user will be taken to a screen that displays a table composed of only those restaurants of that type (e.g. only Italian restaurants, only Chinese restaurants, only Thai restaurants). How would I go about doing this? Any ideas or suggestions?
One possible algorithm outline:
Iterate over your NSMutableArray (e.g. for(item in array)) inserting the category property of each item into an NSMutableSet (or an NSCountedSet if you'd also like the number of times each category occurs)
Use the NSSet sortedArrayUsingDescriptors: method to obtain a sorted array of the categories.
Add the All entry in whatever way suits
The following situation pertains to an iPad app I am working on for my company.
So I have an array of type "Person" that holds the information of a list of people. On the initial page, I have a table that displays their name and picture. When this loads, the results are ungrouped. I was wondering if there was a way to easily group these results with the click of a button based on something like location or business title. The reason they are not grouped when they are loaded is because the powers higher then I deemed it necessary to display the raw list first. Any ideas on doing something like that? Thanks in advance!
You'll want to use "sections" to split the table.
First you need to sort your datasource into the desired groups, and then reflect it in the view.
A dictionary can easily represent the grouped data. Model each group as an array that contains the entries for that group, and then add it to the dictionary with a key that represents the section.
When the data is ungrouped, you can still use the dictionary, but with a single entry, rather than many, and then reflect that in the UI.
That way when you're asked how many sections there are in the table you can return [dictionary count]; and then when you're asked for the number of rows, you can do something like [[dictionary objectForKey#"myKey"] count];
And so on.
When you've reconfigured your datasource you can call [self.tableView reloadData]; to reload the table with the sections.
You'll have to remove the UITableView and add another in it's place via [[UITableViewController alloc] initWithStyle:UITableViewStyleGrouped];. You can't change an existing style at runtime.
The other way to do it, is have it grouped from the get-go, but return 1 for - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; if it is "ungrouped" and return all rows for - (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section when it is grouped, do it the normal way.
I have created a custom uitablecell which contains several values. When the user selects a row, I want to be able to select that row's content for one of the values in the custom uitablecell. If the cell looks like this:
ba_type varchar2(20) P
source varchar2(20) P
row_qual varhcar2(20)
If the user has selected the 'source varchar2(20) P' row, I want to be able to grab the value of 'source' out for my next query.
thx,
wes
Strictly speaking, you've created a tableview cell that displays several values. Sitting in memory somewhere behind that is an array that contains the actual data. That's how MVC architecture works.
Ideally, you have some data structure in memory that corresponds to the cells. If you had an NSMutableArray in memory, you could retrieve the value by doing
// assumes one section in the table view
NSString* sourceForNextQuery = [dataSourceUsedToPopulate objectAtIndex: indexPath.row];
inside didSelectRowAtIndex
If you insist on retrieving the text from the label in the table view cell, when you create the label that contains it, add a tag (mySourceLabel.tag = 999). Then find that tag again by using searching for the tag, the get the text (UILabel.text)
But really, you want to separate the presentation of the data from the underlying model, and have the controller contain the data.
I'm quite new to CoreData and need help with one issue. I have tableview which simply lists cities stored in SQLite db. City is defined by "cityId" and "name" attributes.
Data are fetched using NSFetchedResultsController and everything works fine except that I can't figure out how to make FetchedResultsController to group cities by first letter of city names.
When I supply "name" for sectionNameKeyPath argument of initWithFetchRequest:managedObjectContext:sectionNameKeyPath:cacheName: method, it creates section for each city, which is obviously something I don't want. I can't figure out how to create an expression which would make it work in way I need.
thanks for any tips and/or advices on this
Matthes