list to NSIndexPath monotouch - ios

I am trying to add records dynamically to an already populated UITable. In my UITableView class I have a custom List object
List<CustomObject> _data=new List<CustomObject>();
where I add records to from my webservice call like so:
_data.Add(Json(Object));// Json returns a list of CustomObject
//table is a UITableView
//this.table.InsertRows(_data);
I know this above line won't work because its expecting an NSIndexPath[] but I am not sure how to go about adding the new items an load only the new items added. I don't really follow objective C very well so examples I found don't help so much

Generally, you will add data to your List, and then call ReloadData() on your TableView. You usually only call InsertRows() if you want to insert data at a particular spot in the table based on some sort of user action.

You are trying to add a List of CusomObject as CusomObject to a List<CusomObject> ,that is not quite right.you should be adding a CusomObject to List<CusomObject>.

Related

UITableView reloadRows only works every other time

I have a custom UITableView ('table') fed by a data array (e.g. 'rowVals[]') which does not display correct values after making a data change.
Error Case
Init table to 5 rows with values fed by 'rowVals' = ["R1" - "R5"]
post - displays correctly
Change rowVals[1] from "R2" to "S2"
post - shows init values (e.g. w/"R2")
Call table.reloadRows() on the table
post - shows new values (e.g. w/"S2")
(BUG!) Call table.reloadRows() on the table
post - shows init values again! (e.g. w/"R2")
Steps #3/#4 now cycle repeatedly!
Question
Why is this occurring, where is the table finding "R2" to display? I have spent over two hours debugging this to no avail, yikes! Thoughts?
Thank you for the suggestion Paulw11, with debugging and persistence I was able to resolve and correct this.
Problem Source
Custom cells, initialized on viewDidLoad() in vc
Problem Solution
Have tableView(cellForRowAtIndexPath) return the cell directly, not by dequeueReusableCell()
I am not sure entirely why this corrected to problem but it does somewhat make sense, dequeueReusableCell() returns a new cell when the 'identifier' is not found!

do tableView.reloadData() in external class

I am doing a Parse query from an external class. This query give me back the array for populate the tableview, so in the viewDidLoad method I call MyClass.load(array) and the async parse method findObjectInBackground return me the array filled but in the time that the findObject retrive me the objects the tableView is already created and I see an empty tableView, I did a fast google search for the problem and I found that I have to use the self.tableView.reloadData() method, I tried it but I am in an external class and the delegate for the tableView is in the tableViewController, there is any way to refresh the tableView from an external Class?
If you need some code example just ask it, thank you!
EDIT I'm using Swift 2.0
You need to set custom delegate between your external class and ViewControllers.
check for creating custom delegate
Also, you can use NSNotificationCenter for send and post notifications. please check link

Vaadin table row change best practice

What is the best way to replace a table row in Vaadin (6 and 7)? I use BeanItemContainer. The bean is an entity and has changed (not the ID).
I think this cause unnecessary method invocation and/or object creation:
table.removeItem( item );
table.addItem( item );
As I know, the best pratice is:
BeanItemContainer<DataModel> tableDataSource = new BeanItemContainer<>(DataModel.class);
table.setContainerDataSource(tableDataSource);
When you want to replace a row, just replace the data of this row in tableDataSource:
tableDataSource.removeItem(item);
tableDataSource.addItem(item);
The difference between your code and mine is:
In your code, you replace the row (it means the row is removed from the table and then a new row will be added to table).
In my example, I just replace the data of row.
Hope it helps

how to record the order of a tableView managed by a NSFetchedResultsController

I have an NSFetchedResultsController to display a tableView.
And users are allowed to change the cells' order.
How can I record the order so that when users go to the view again,
the table displays by the order modified by users last time?
Thanks a lot!
Hey guys I've done this.
In order to re-order managedObjects fetched by a fetchedResultsController, the most official way I think is to give the entity another attribute of int, such as "order", and give this attribute to the fetch request of a fetchedController, and in table view delegate method "move row from .. to " something like that, deal with this attribute with your hands, and if you use a fetchedController delegate, set a flag in that delegate methods to indicate that you will modity the entity yourself, and notify the delegate to do nothing but return.
Sample codes are Apple Sample code Recipes, and hints on the documentary of fetchedController!

How to delete items from ListField

I want to delete items and refresh it. I have been trying for 2 days, no luck.
listField.delete(index) doesn't work.
If you can provide me appropriate solution, I will give you all of my reputation.
You'll probably have to override it to remove the item from your data backing the list, and then call listField.setSize(newSize). Since it doesn't know what sort of data structure you are using to push elements into it, it can't be sure how to remove them.
For example, if you have a Vector that stores your data, override delete() to remove the element, and then call setSize(vector.size()). If your ListFieldCallback is stored somewhere else, just make a wrapper call to a similar delete() method in your callback.

Resources