I am trying to grab the data from the database and display all the values in sorted order grouped into sections from A-Z and also my UITableView is indexed. In this case the indexes are A-Z. The strange thing that's happening is when I get all the values from the DB onto the table, I see that values under section 'B' has some values from section 'A' and if I tap on any index for example if I tap on index 'D' and come back to letter 'B' section the values that used to start with A are now replaced with D.
This happens only to section 'B' values in particular. All the values in other sections are displayed correctly. Sorry if the question is not clear. This is the best way I thought that I can describe my problem.
Please I need your help. It is very urgent to finish off this task and I can't understand why this is happening.
Look at the TableView Suite sample code. There's a little thing called "cell reuse" that you are running into, and you'll want to clear that up before you continue on with this problem. It's the most frustrating thing to deal with with respect to tableviews if you are not familiar with it, but it's a memory use optimization that makes sense once you understand what's going on.
Related
I have a large spreadsheet: 700+ rows, each having references to the previous row. I use reference functions: ROW(), COLUMN() and INDIRECT(), ADDRESS(). (Yes, I have considered fixing values every 50-100 rows to reduce calculation trail.)
Until recently I used OpenOffice.org and it worked fine. LibreOffice, however, when the file is opened, seems to give up after some rows and further calculations become Error 522. Sometimes a change makes it re-calculate it all and errors disappear and doesn't reappear when I undo the change. I have also found out about Ctrl-Shift-F9 (must be re-calculate), which also makes errors disappear.
Even though the file has been saved and re-saved by LibreOffice several times it still reports false Error 522 when I open the file, so it doesn't seem to be compatibility problem.
Is the problem that a very long branched out calculation trail makes the software think it will never get to the initial values and therefore it must be circular? (Which my idea of fixing values would solve.) Or could there be something else I may have missed?
UPDATE
I don't see how INDEX() would help. I want to refer to a cell immediately above or a cell from a row immediately above. Cell d46 could point to d45 or b45 or $a45, and that would work when copying a row, but not when inserting or deleting a row: If you insert a row just above, the references pointing 1 row above would start pointing 2 rows above, so each time I would have to edit the formulae. The row (each row) contains several references to the row just above, so I thought the easiest way would be INDIRECT(ADDRESS(ROW()-1,COLUMN())) for the same column or INDIRECT(ADDRESS(ROW()-1,1)) for column A... Any better solutions?
I do not know the specifics of the problem, but it sounds like it would help to simplify the formulas, as you suggested.
Another possibility is to write macros to handle some of the calculation work. Besides Basic, macros can be written in Java, which you seem to be familiar with. Macros can be called from a spreadsheet function, or called when the document is loaded.
It may also help to use a more powerful tool such as LibreOffice Base with MySQL. Often spreadsheets that need a lot of INDIRECT() and ADDRESS() are really using database-type logic.
I'm right now experimenting with a nodejs based experimental app, where I will be putting in a list of books and it will be posted on a forum automatically every x minutes.
Now my question is about order of these things posted.
I use mongodb (not sure if this changes the question or not) and I just add a new entry for every item to be posted. Normally, things are posted in the exact order I add them.
However, for the web interface of this experimental thing, I made a re-ordering interaction where I can simply drag and drop elements to reorder them.
My question is: how can I reflect this change to the database?
Or more in general terms, how can I order stuff in general, in databases?
For instance if I drag the 1000th item to 1st order, everything below needs to be edited (in db) between 1 and 1000 the entries. This does not seem like a valid and proper solution to me.
Any enlightenment is appreciated.
An elegant way might be lexicographic sorting. Introduce a String attribute for each item. Make the initial length of the values large enough to accomodate the estimated number of items. E.g., if you expect 1000 items, let the keys be baa, bab, bac, ... bba, bbb, bbc, ...
Then, when an item is moved from where it is to another place between two items, assign a value to the sorting attribute of the moved item that is somewhere equidistant (lexicographically) to those items. So to move an item between dei and dej, give it the value deim. To move an item between fadd and fado, give it the value fadi.
Keys starting with a were initially not used to leave space for elements that get dragged before the first one. Never use the key a, as it will be impossible to move an element before this one.
Of course, the characters used may vary according to the sort order provided by the database.
This solution should work fine as long as elements are not reordered extremely frequently. In a worst case scenario, this may lead to longer and longer attribute values. But if the movements are somewhat equally distributed, the length of values should stay reasonable.
I have about 20,000 records (coming from an SQLite db) that I need to present to the user for possible choices, so conventional picker control is out of question.
Another possibility could be an indexed UITableView where user could check the desired value, however keeping all the 20K records in the memory doesn’t seem like a good idea.
how should I go about implementing UI for it? EDIT: is it possible to do something like auto-complete combo-box?
I'd look at some sort of nested UI i.e. a UITableView that has just A, B, C etc to start with and when the user presses on a row show another table view with all the results starting with A.
There would need to be a query that got the number of results that started with A, B, C etc so you only showed letters in the first table that actually has results but then each query in the second table would be very simple - all results starting with 'A' etc.
You'd never have to load all 20,000 results into memory at the same time :)
However, you should probably make sure that you have an index on the field that you're querying, otherwise your queries are all going to be rather slow :(
The other solution is to use a search box at the top of a table view - the user types in letters and each time the list is reduced to only results starting with that letter. That's a pretty simple query to implement :)
However, you would then still have the problem of what to do if the user hasnt typed anything in - do you show a message asking them to type or do you show all 20,000 results in an enormous list?
Are you aware of UIPickerView's "components"? 20,000 choices might be pushing it, but it is certainly one way (that is familiar to users) to narrow down choices by an order of magnitude with each spin.
If you find yourself constrained in one dimension, you could implement master-slave picker views.
Normally to use UITableView, the number of sections and rows per section are known. But what if they aren't? I want to implement a lazy search, so that I actually search for the next match when new data needs to be displayed. Something on the lines of: db.prepareSearch(query) and then call something like db.nextSearchResult() when it is time to display a new cell. The search result determines if a new section is required or not (search results are inherently sorted).
Not sure why it wasn't done this way to begin with, so that it asks for a section until no more are available or needed, and for cells in the section until no more are available or needed, instead of having to specify the totals, which implies having to finish the whole search before starting to display the first few results.
To get the number of sections and rows, it's easy -- ask your data source. If your data source has no way of telling you this, make a way.
For instance, if you have to query a table and ask how many rows there are for your sections, do that. Then, for each section, ask how many rows there are which match that section.
What it also sounds like is you want to paginate your data. Meaning when you get to a certain point, have a "load more data" cell or some-such. This is fine too, just add a sentinel node to your data source, and whenever that particular item comes up, display your alternate cell while you load your data, then remove it after your next data is fetched. I do this in a few of my apps.
If I'm understanding this correctly, at the point of drawing/populating, you will know how many rows/sections you have.
If your changing the underlying data using db.nextSearchResult() then you must be calling [tableView reloadData] to trigger a UI update, at this point you should know how many sections and rows you have.
I have to admit I'm a little confused to the exact issue here.
I am having trouble grasping the concept of multi component uipickerviews. I really would like to just OWN this subject. I would like to make a 4 component pickerview with components that are dependent on one another.
The first component is being populated from an array from my db, and that is showing up fine. I have all of the other info available in arrays, but I am just getting hung up on the dependent aspect of my pickerview. I figure the best way to make component 2's data depend on comp 1 is to link them somehow within the didSelectRow section. But I don't know the syntax.
I have been working at this for hours now and feel like I am really close, but I just need some help with a few issues. What is the syntax for connecting components so they depend on each other? Something like this? (Which is awful I know, but I am thinking that is the direction I need to get) :
if(picker = pickerComponent1)
//set number of rows for comp2 and also the content etc...
Another issue is determining the numberOfRowsInComponent bit because they aren't in the same method...
If anyone knows about (or wants to give :) a tutorial on this subject, it would be so helpful! Or if you are knowledgeable on the topic and would like to share some of what you know, that would be perfect too. I would really like to see this seemingly simple task completed.
It's quite simple. In the pickerView:didSelectRow:inComponent: method, just call [myPicker reloadComponent:] for all components coming after the one where the selection changed. The picker will then automatically ask its datasource (your view controller, presumably) for the number of rows and the rows' values.
Then, in pickerView:numberOfRowsInComponent: and pickerView:titleForRow:forComponent:, return the appropriate values (the count and contents of the corresponding array) depending on the values of the parent components' selected rows.