A proper way to reduce provided data set in UITableViewController - objective-c

I am provided a reference to a NSArray that contains data items. In my Custom View controller that acts as a data source for the table view, I interpret each item and present it as a cell.
So far so good.
Now there is a requirement from my colleagues to implement a filter, that will be based on values of one of the item's properties.
This property has enumerated values (4 of them). So when I apply the filter, i should see only items that match the particular value.
My question is how should I approach this filtering of that data.
1) Should I set the _data private variable to point to the original data source, and then override the "data" property getter to take into account the filtering?
2) Should I generate a separate filteredData array inside my controller?
3) Some other approach?
NOTE> coredata+fetched resultscontr. is out of the question. The number of items never will be more then 150-200.

I would go with the second choice. Having a filteredDatasource is more convenient. This way, you are able to know , not only the cells you should display, but also how many they are etc. Moreover, if in the future you want to sort them and use sections, you will be far more flexible.
For example when you implement the method – tableView:numberOfRowsInSection: which is called many times internally using the filtered data source you do not have to traverse through the array's objects many times so as to see which of them should pass the filter. You just return [filteredDatasource count]. This is more efficient.

In the apps I work on we have a array of all items and a copy which is the one the datasource refers to. When a filter is applied it replaces the copy but is based on the original array. So I guess #2.

Related

Issue on hiding multiple columns with NatTable

I need to programmatically hide multiple columns of a NatTable.
To do that, I compute an array of indices with a method and then I
invoke the MultiHideCommand as follows.
int[] indexArray = idxToHide.stream().mapToInt(i -> i).toArray();
_tableView.doCommand(new MultiColumnHideCommand(_tableView,indexArray));
What I get is that only a bunch of columns are hidden, but not all the columns in the indexArray.
I read that the ColumnHideShowLayer has been designed with UI interaction in mind.
Is there a right way to programmatically remove multiple columns?
First, the command takes the positions as parameter, not the indexes. Second, the positions need to be based on the layer that is used as first parameter. If a ViewportLayer is involved, non-visible columns won't be taken into account.
So you could try to calculate the positions based on some lower layer, e.g. the SelectionLayer, and then pass in the SelectionLayer and the positions based on the SelectionLayer on the command. That should work in theory.

How can I see all the key-value pairs in the `myShape.Cells()`?

I'm recently programming with the VB in the Visio.
I'm really curious about the myShape.Cells("Width") and myShape.Cells("PinX"), I mean the .Cells("...") part of the code. My program has used them very many times.
I want to know more about them, but I can't find any specific explanation about this.
Who definites it, and what are all of the key-value pairs in the .Cells().
I've seen someones in this site using someShape.Cells["Width"] to point to the value of the shape's width.
So:
I want to know if the .Cells() is an collection or map(dictionary) in reality. Please give me some explanation or files that I can read for help.
I've tried to put the myShape.Cells or myShape.Cells() in the watch window, but it didn't work. It told me something wrong..
So How can I have a look at all the key-value pairs in the .Cells(), it will be a great help to give me some codes that I can use to show the key-value pairs in the immediate window.
Thanks a lot.
There are two ways of accessing ShapeSheet cells in Visio. One is by name, using the Shape.Cells (or CellsU) method you mention, and the other is by index using Shape.CellsSRC. The second method reveals how cells are structured, by Section, Row and Column. Note that slightly confusingly, the SRC structure is not necessarily an exact replica of the cells you can see when you open the ShapeSheet in the UI, which is organised into something that's a little more user friendly.
The SRC indices are usually expressed as enums, which you can look up in the SDK along with the cell Name equivilent.
So to answer your questions more directly:
Is .Cells a collection - not one that you can call and retrieve all values. You can loop through the cells using CellsSRC but you'll discover that the cells are not necessarily contiguous, plus there are a number of unnamed or internal cells that you can't use via the api. For further details you might find this link useful https://msdn.microsoft.com/en-us/library/aa201764%28v=office.10%29.aspx
myShape.Cells() doesn't work - The cells method takes a single parameter, which is the string name of the cell. This is often, but not always, the name you see in the ShapeSheet window. Otherwise you have to look up the name in the docs - Cells reference
One last point is that you should try and use the CellsU method rather than the Cells one. The former accesses the cell names using universal syntax where the latter uses local syntax, which may differ across different locales.

Best way to handle multi-valued fields as a view/grid

In several notes applications, instead of handling related data as separate documents, if the size of the data is small (less than the 32k limit), I'll make several multi valued fields and display it in what I call a "List Panel". It's a table where each column displays one multi-value field. Since fielda(1) goes with fieldb(1) that goes with fieldc(1) there is a concept of rows. (I did a similar thing in my auditing routine discussed here )
It is always assumed that each field has exactly the same number of elements.
All the multi-value fields are then stored on the single document. This avoids several coding conventions that made my eyes bleed like having date changed, who changed it, new value fields for each field we wanted to audit. Another thing that this kept to a minimum was having to provide multiple fields for the same thing that locked you into a limit. Taxrate1, Taxrate2, Taxrate3, etc...
In my "Listpanel" the first column is a vertical checkbox. (One for each element in my lists) This is so I can select one item to bring up and edit, or select multiple values to delete "rows" or apply some kind of mass change to them.
What would be the best way to handle this under xPages to get this functionality? I tried making a table but am having the devil of a time to get the checkboxes to line up with their corresponding data items.
Views and dojo-grids seem to assume we're using a document for each row.....
This TableWalker may provide what you want http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Tutorial-Introduction-to-XPages-Exercise-23
It was created when XPages was all very new, so it's SSJS rather than Java. But if you're comfortable wiith Java, converting it probably won't be a challenge.
You could use a repeat control to display the values and build a table using the table row tags in the repeat. You would want to calculate the id of the checkbox to be able to take an action on that selected row. The repeat var would be just one of your multi-value fields and you use the index of the repeat to get the value for that row from the other multi-value fields.

How to insert data into objects iterated by Yii CActiveDataProvider

I have a strange request and I'm not sure there is a better way other than simply brute force, but I have a CActiveDataProvider being rendered and virtual properties of the underlying Model are being used.
I would like to be able to pass extra information to that Model to filter the calculations in those virtual properties.
For example, assume there is a virtual property method getCreated_Widget_Count() that returns the number of widgets that the entity (let's say it is a widget maker) has created it its lifetime.
I would like to be able to filter the count to a specific date range.
So I want to be Create a CActiveDataProvider and use it in a CListView to display each of the elements, and the view is accessing property created_widget_count. But I want it to, sometimes, limit the result to a number based on an date range.
The obvious thing to do is iterate over the entire data set first and set the range to filter in each object, but I was hoping that there was a way to pass information to the CActiveDataProvider that could get into each constructor so that could be done while they are being built.
Any ideas?

Creating a Rails partial that is resource-agnostic

This question is related to my previous question, Creating a Rails partial that is model-agnostic.
I am trying to create a Rails partial that is given a variable, say, seasonal_type, and does several different operations, such as querying a resource, and accessing instance variables, based on the value of the variable.
To be more concrete: I have the two models SafetyTest and TeamDue, which belong to Student. In one particular case in this partial, I need to call either
#student.safety_tests or #student.team_dues. I would like to pass the variable seasonal_type to the partial and like that determine which of the two is executed. How would I be able to do this? The value of the variable could be whatever is most convenient, such as a symbol (:safety_test) or a model (SafetyTest).
There is also another part to this question. In my controller, I precaculcated some instance variables for SafetyTest and TeamDue, such as #valid_safety_test and #valid_team_due. In my partial, how can I use either of these two instance variables, based on the value of seasonal_type? Or should I just calculate these values inside the partial, even though that would be against the MVC structure?
Any help would be much appreciated.
Here is the answer:
In my controller, I created an array with the models of both seasonal types: [SafetyTest, TeamDue]
Then I iterated over this array, and used the model to query all the information that I needed from the database. I put that information into an array and passed it on to the view with an instance variable. So this array also has two items, one for SafetyTest and one for TeamDue.
Then the partial iterates through this array and renders the view necessary.