I'm using UITableView with UISearchBar.
In this case I have two tables and two arrays (All/filtered)
How can I delete a row?
I can set If statment, and delete message from filtered array, but allMsg array still consists it.
use temporary array and insert all filter array data except deleted data from filter array and reload table by using data source from temporary array.
Related
I have a UITableView which I populate by a list of objects I'm getting from a Realm database. What I want to do is to create sections and group items in the list by a property value in runtime.
All of the examples of grouping items in UITableView I see online are operating with it a prearranged dictionaries.
Is it possible to do?
You can set up your table view data source any way you want. You could write code that decides on the fly which items belong in which sections, but I would advise against it.
I would suggest setting up a method that takes your list of Realm objects as input, and builds an array of sections containing sub-arrays of the rows. Then your cellForRowAtIndexPath method can simply index into your model data like normal.
I have a UITableView and an array for data source of it.
But I don't want to use all objects in the array but some of them.
since I need that array fully later, I don't want neither remove any objects from array nor filter the array with the desired objects.
Any suggestions?
You will have to have two arrays:
1- All items are stored in original array;
2- Second array with indices of the items to show in the table
arrOne[arrSecond[i]]
would be the item number i in the table
You need another array with the list of filtered items.
I have a table view which populates from an array of strings. Using UIGestureRecognizer users can reorder the cells and save the new order.
When pressing Save I need the new order of the cells to save to the array. I have tried many different techniques without success.
How can I capture all the current cell texts in order?
Don't rely on the cell contents as your data source. When the user reorders the cells, update your backing array to match (or a copy of it if you need to be able to revert changes).
That way, when you want to save, everything is already in the correct order.
I have a NSMutableDictionary that I use with a UITableView, in the table each section header is the value of a key and the cells for each section is derived from the key's value (an array).
I would like the table view to have a specific key at the top and am not quite sure how to do that.
I suggest changing your data structure to an array of custom "TableSection" objects. Each object would have a header property and an array of values for the cells.
Storing the "TableSection" objects in a mutable array lets you order them whatever way you need.
A dictionary (NSDictionary or Swift Dictionary) is not suitable for storing the contents of a table view. Dictionaries are inherently unordered, and a table view must have its contents presented in a consistent order.
You can certainly use an array of dictionaries. That's pretty common. For a sectioned table view an array of arrays of dictionaries is quite common (outer array has an entry for each section, and inner array has an entry for each row in a given section.)
If you have special contents to go in the section header you can create a section object that has a header object an an array of row objects (dictionaries or custom "row" data objects), and then have an array of section objects. Then you make your data source methods serve up cells using whatever data structure you come up with.
I have a view with UITableView and I populate NSMutableDictionary and bind it to UITableView.
I add items like: c,b,a,d but data in table are displayed like: a,b,c,d.
Is it possible to disable ordering so items will be displayed in table in the same order as I added them in NSMutableDictionary?
If the order objects are displayed in your table view matters, you should be using an NSArray or NSMutableArray. These are the only Objective-C collections for which the order can be guaranteed, and they work a lot easier with table views than any other collections, given that their objects are stored at indexes and these can match exactly to the row portion of the NSIndexPath argument of cellForRowAtIndexPath:.