How do I rearrange my UITableView with respect to alphabets or with respect to modified date - iphone

I have two table views displaying the data from a Sqlite database.
I can modify the content of the 2 tables. One displayed date and data. One displayed data only.
I.e. I can change date & time,words as well.
Now I need to arrange the content with respect to date in 1 table,
with respect to alphabets in 2nd table.
What to do?

You can use a sortDescriptor to sort the array (or fetchRequest when using Core Data) you're using. If you've setup your tableViews any other way please provide some more information.
Documentation: SortDescriptors
Once sorted you can reload your tableView: [tableView reloadData];

You must be storing your data in some data structure (like array, dictionary etc.), once you edit the date and time, Sort your array or dictionary using sort descriptors and then reload the table

Related

Re sorting fetchedresultscontroller once the data is fetched

I have a situation where i need to sort the data using multiple sort descriptors. I want to sort the data initially with two components which are numbers in descending order. Then I should show the data on the table view sorted with name component and use the sectionNameKeyPath to get the sections.
I want the data should be sorted out first with the two specified components and then the result with name. Is this possible using NSfetchedResultsController. I am using this fetchedresultscontroller in data source for tableview. Is there anyway to re sort the fetchedresultscontroller?
I can sort it by taking an array and using sortdescriptor on that, but I want fetchedresultscontroller to show the section details and etc.
Is there any way?
I don't really sure if I have understood your answer.
But there is a property called sortDescriptors in NSFetchRequest which you may use it to sort.
And it's an array so you can supply multi NSSortDescriptor objects
And if you want to resort it.
I know two ways:
Store the result in an array like you said and resort it.
Change the sortDescriptors and re performFetch of the FRC

In What Order UITableView sections are displayed?

I am getting data from a sqlite3 database and i'm saving those things in an array and i'm using that array in viewForHeaderInSection method, every time my data will be different i mean section list will be different every time it is displaying randomly i need to display it in an order.
1. How a UITableView displays its sections(any sorting algorithm is there) or randomly it will display?
2. How can i sort my sections in an order?
Any help is thankful in advance.
The table view displays its sections in the order you tell it to. If you are populating an array for the sections from a SQL query, you can apply ordering in the query. If this is not possible, you can sort the array after population using one of the many sorting methods available on NSArray, for example sortedArrayUsingDescriptors:. See here for more:
http://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html#//apple_ref/occ/instm/NSArray/sortedArrayUsingDescriptors:
Question is a bit unclear. Better if you can post some code. You get different data from sqlite each time into array and that data is shown in sections. So why do you need to sort sections ? Instead, sort the array according to requirement and show the sorted data in section.
Are you asking about the order of the sections or the order of the content within the sections? For example:
Section 1
Section 3
Section 2
OR
Section 1
Row 1
Row 3
Row 2
Only the order of the Rows is determined by the order of the datasource of the uitableview.
i think you are getting different unordered data form sqlite database into array.you want sort the array(arrList)data
arrList = [arrList sortedArrayUsingSelector:#selector(localizedCaseInsensitiveCompare:)];
NSLog(#"%#",arrList);

Dynamic Sections UITableView with Unknown cells

Hey,
I'm basically trying to retrieve data from SQlite db and populate a tableView from it.
The sql-data-retrieval method creates two arrays. "dataArray" and "SectionArray".
DataArray is filled with data NSObjects.
Uptil this point, i can create the appropriate Section headers.
Here is the problem,
-1 What do i do to make sure that the right objects get into their appropriate sections and not under any other sections (which they seem to be doing). Also the Count(number of rows) in each section differs.
What should the code be in "NumberOfRowsAtIndexPath" and cellForRowAtIndexPath methods
-2 What kind of datasource objects are more suited for this type. I'm simply filling up two NSMutableArrays - dataArray(rows) and SectionArray(Section headers).
I think you should make many NSArray one for each table header you have created. In NumberOfRowsAtIndexPath you will return the count of the array for the requested section, and in cellForRowAtIndexPath you will choose your array using the section index (as before) and with the row index you will select the row of that array.

Separating UITableView data into sections from one source

I have one table in my core data source which holds some articles with NSDate's. I basically want to separate the NSManagedObject into days, so you can scroll through and separate articles by date.
What is the best way to approach this? My context is queried out in descending date order, so just need to split that up into days for the UITableView sections, rather than 1 big section.
When you load the data for your table -- whether that's using NSFetchedResultsController and Core Data, or loading a .plist file into an NSDictionary object -- you can "section" it as you like.
You'll first step through the data (e.g. use the fetchedObjects property if using NSFetchedResultsController) and determine what sections you want. Since you're wanting to split on dates, you might store cutoffs represented by NSDate objetcts in an array. You would then use this array to implement the various UITableViewDataSource methods: in numberOfSectionsInTableView: you can return the count of this array, and in sectionIndexTitlesForTableView: you can return NSString representations of those stored NSDates for the section titles.
Methods like tableView:numberOfRowsInSection: and tableView:cellForRowAtIndexPath: are a little trickier. You'll probably want to use another "preprocessed" data structure (perhaps a two-level array of arrays, where the inner arrays contain the entity objects you fetched), and you'll want to set up as the same time as your array of NSDate objects.

iPhone UITableView populating variable rows sections from flat array

I thought that would be very common and easy iPhone App. In the main app I connect to database, retrieve values from database (NSDate converted to NSString)n and put into single array. Then in one of the views I populate UITableView with elements from the array. UITableView is grouped (sections). I step through array to discover number of sections (change section if new day). How do I retrieve correct element of array in cellForRowAtIndexPath? IndexPath.section and IndexPath.row seem useless as row starts count from zero for each section. If number of rows in each section was the same it would have been easy:
[arryData objectAtIndex:(indexPath.row)+indexPath.section*[tblMatchesView numberOfRowsInSection:indexPath.section]];
But number of rows in each section varies... :-)
Separate your data into arrays of arrays (based on the number of different days) once you get it from the database, that'd be the simplest solution...
How about storing different date sections in different arrays? For example, you can have an array A of array. You can loop through the original arrays yourself, if you found a new day, you just create a new array and put it into the array A. And then, when you loop over the cell, you can get the section number to get the correct array and based on the row number to get the correct elemenet in the array
It doesn't have absolute cursor but you can try utilizing
UILocalizedIndexedCollation class which is used to ease the "sectioning" of your data and proving the tableView delegate functions the required data such as the index titles, etc
Here's apple documentation link for it:
https://developer.apple.com/library/ios/#documentation/iPhone/Reference/UILocalizedIndexedCollation_Class/UILocalizedIndexedCollation.html#//apple_ref/occ/cl/UILocalizedIndexedCollation