iPhone tableview pagination - iphone

First, please believe me when I say I did search for this answer first... a lot. I found many examples, but none performing similarly to what I need. Though I could have been searching using the wrong key words, I don't believe so.
Here is my issue:
I have a table view being populated by a query that is returning a huge amount of data. The data is for a list of restaurants, a price rating, and id. But there are so many restaurants in the database that it fills memory and crashes the app most time. (I am assuming this is what is going on, as the code works just fine if the query is limited, and has always worked on other pages I query things that don't have as much data returned.)
What I would like to do is make pagination for the application's table view for this page. I don't see how I could use the "Show More" method, or the auto load when scrolled to the bottom, simply because if you scroll down to the end of the list, you will still have the same issue: filling memory. Is there a way to do web-like pagination where (if they are not on the first page) they have a "Previous" cell at the top and (if not on the last page) a "Next" cell at the bottom? These would have to clear the cells out in the current view and drop the data so we're not just adding data which would cause the same issue, then do a new query to populate the cells.
Of course, I do not expect someone to sit here and write all that code for me. The main part I would need is just how to set up the cells for the next and previous cells. I should be able to figure the rest out after that, but I don't know how to go about clearing the data from the current table view.
Thanks for any help or suggestions.

I think you can do with a show more method or loading as you scroll, you say the problem is that you still load a bunch all the data and youll run out of memory, but you can avoid that... One option is, save to disk or just release data that isnt being shown on the table view, you can use indexPathsForVisibleRows method of UITableView to see which cells are visible, and with that info you should know which data you can safely release... You can do this either when you receive memory warnings, or maybe as cells are scrolled off the screen (up to you)...
Hope this helps
Daniel

Related

How Do You Filter and Sort Data in a CollectionView

I have a CollectionView on a page that is displaying data from a List<> of items. I do sorting and filtering in a code behind on the page by changing the List with LINQ, and then setting the BindingContext of the view, like this:
MyView.BindingContext = FilteredData;
On IOS this works fine, every time, no problem. On Android, I can change the data a few times (it varies - normally three to five) and then the page doesn't display any data. In the debugger I can check and still see the ItemsSource has all of the items, but nothing is displayed. I then "switch" to my other view on the page, which is done by hiding one DataGrid row and showing another, then "switching" back. The data still isn't displayed, but after I do that I can run the code again that does the sorting and filtering and it starts working again - the data is displayed on the page. Not only that, but after I do that, it works every time from that point forward on Android.
I've spent hours trying every thing I can think of to try and find an event or property or anything that would indicate when this problem occurs so I can try and find a work around for it. I'm at a complete loss; wondering if there are suggestions for how to capture and/or fix this problem.
I did find a combination that worked to resolve this issue. I changed the page so that the CollectionView at issue is in the Grid row that has a non-zero (i.e. visible) height when the ContentPage loads. After doing that, the code works as expected. Previously, it was in a Grid.Row whose height was set to an absolute 0 when the page loaded, and then the height was changed to a non-zero value when a button was clicked.
FWIW, this is similar to other issues I've seen with MAUI on Android, where the visibility of certain controls as well as the order in which you modify them can interfere with rendering data binding results.
I solved sorting using a SortedList and made the list items inherit from IComparable, but I don't love the solution because a SortedList is not an ObservableCollection, and because implementing IComparable can be tricky and leaky.

How to load elements in a table fully, to retrieve all IndexPaths?

I have this function in which I access from other classes to retrieve the indexpath of the relevant cells so I can edit the data within the cell dynamically across the App.
The problem is, when I update cells modified previously, I would like to modify them again once a user closes and re opens the app, but I am unable to access the cells past the 10th row. And I am assuming it is due to the fact the TableView only loads whats viewable at the moment.
Is there a way to force load all cells? Is my theory behind the problem right? Or is there a different approach I should be going about to this.
Instead of writing directly into the cell, you should write towards a centralized data source (or Model by the MVC pattern).

auto complete a search

I have searched the questions so far, and it seems that most auto complete questions are about the console.
How can we auto complete a search and load it like the image below. I am new to xcode, so if you have instructions on what I need to do to get it to look like this, then I will appreciate it.
Basically I have an empty table cell, when i touch it to edit, a search box should come up (at the top), and as soon as I type a, all the values for a show up below in individual cells. I can select a cell when I see the value, and it will take me back to the original table and input that value into that cell.
What is the structure after i click the initial cell to bring up the search box
Auto complete with cells?
After this, I imagine I store the value of the variable, and assign it to the cell it originated from.
Attached is an image for reference.
Thank you in advance.
PS - The list to auto complete from has a few thousand values.
Thanks!
For several thousand entries it's unlikely Core Data will give you good performance. Instead you'll need to load the data as a Directed Acyclic Word Graph (DAWG). See other answers on this for further info.
Directed acyclic graph
Best way to implement address book autocompletion on iPhone?

How can I change a ViewController list (by changing predicate) without popping and pushing?

I have a ViewController whose view results from data from a fetch request with Predicate 1. I'd like to repeat the fetch request with a more restrictive Predicate 2 that will give a SUBSET of the data using Predicate 1.
Then I'd like to update (and possibly animate) that view on the iPhone screen by pressing a toggle button, so that the old and new views expand and collapse the rows. (I don't want to do this modally, as I'd like the user to see which rows came from the old rows.)
I'm thinking of something like the Phone application on the iPhone. Under the "Recents" tab, you'll see "All" and "Missed" buttons. When you press these buttons, it switches between showing all calls and just the missed ones by expanding/collapsing the rows. As far as I can tell, this is not a modal transition.
Can someone give me pointers as to how to do this?
If your view is a UITableView, you can use a combination of
-deleteRowsAtIndexPaths:withRowAnimation:
and
-deleteSections:withRowAnimation:
as well as the corresponding -insert methods, if applicable. You can batch multiple changes (so they animate at the same time) with -beginUpdates and -endUpdates.
I'm not aware of any way you'll be able to do this that doesn't involve iterating over one of the two sets and repeatedly calling -indexForObject on the other, though.
I found a way to expand/collapse rows by changing the heights of each cell, using tableView:heightForRowsAtIndexPath:indexPath:, as in:
http://www.alexandre-gomes.com/?p=482
Hope that's helpful to someone!

Creating an alternative way to scroll TableView on iPhone

I currently have a TableView with over 35,000 cells. Obviously the standard iPhone flick-and-scroll becomes inefficient with this many cells. I have already implemented search but still think that a way to scroll the entire table is necessary. I am currently using the
-sectionIndexTitlesForTableView:
method to populate the side with the relevant characters, and I want similar functionality to that in Apple's Remote app. I do not have section titles in my table and simply want the sectionIndex to be an alternative way to scroll through the entire 35,000 cell table. How should I go about doing this?
My instinct tells me that a list that large could probably be broken down into smaller sections that could be filtered using the standard hierarchical navigation on the iPhone - that said, without knowing what exactly the data is I can't say that with any confidence.
You say you don't have any section titles - is the list alphanumeric? If so, what is wrong with having a standard alphabetical sectionIndex and sectionTitles?