if i reorder rows on my table view, is it possible to save the result only if the user pressed the "Done" Button?
(Reorder is working great, but i only want to commit the final result of the positions if the user pressed the Done Button, and not every time a row is moved.)
Is there something like editingStyle == UITableViewCellEditingCellMove in commitEditingStyle?
Or is this only possible in the moveRowAtIndexPath action?
Thanks for help!
You will need to create some "editing" version of your internal data structure that you commit when the user finished editing. UITableView does not keep track of where the cells are; it relies on you to do that. It just tells you when the user asks to move things. If you don't really want to move them at that point, then you'll need to keep track of where they really are versus the current order in the TableView.
Remember, UITableViews are intentionally dumb. They don't keep track of data. They just draw things. You keep track of data (as the data source), and tell them what to draw when they ask.
I generally recommend that developers separate their actual data into a separate model class, and have the UITableView maintain a separate NSMutableArray based on that model class. In that case, during editing, you would update the UITableView's array, and when finished editing, it would send that array to the model to update the "real" data.
Related
i have a checklist that is on a UITable View. The user can add/delete cells and check them and uncheck them. I need some assistance with saving the state of the checklist when the page is left, becuase when the user adds a new cell, leaves the page, and returns, the table view is back in the original state i had made it be in! Does someone know my problem? Thanks Guys :D
-Kurt
What you appear to be missing is that adding or deleting a row from your table does not update your source array. Typically when working with a UITableview there are three steps you must perform:
add or remove the tableview cell
update your source array (presumably adding or deleting objects in your context)
save your context to commit the changes
This is assuming you are using Core Data for persistent store. If you are saving in memory than you are likely done at step 2.
I suggest you review the UITableView Class reference, look over the examples and step through a tutorial before trying to stumble through the process.
I'm working on adding the functionality to delete a row in a UITableView on the iPhone. It's pretty clear how to delete the row within the application, from both the model and the UI. However, the deletion requires a call to be made to the server, which can't be guaranteed to succeed given all the funkiness that can happen with mobile connectivity. I'm implementing both swipe-to-delete for single rows and switching the entire table into editing mode.
What kind of behavior can be used within the UITableView/UITableViewCell to indicate a server call in progress? I think this can be tricky with the limited real estate.
Should the user be permitted to delete other rows while a delete call is in progress?
What behavior is recommended for errors? Displaying a UIAlertView?
Change the accessory view of the cell to a UIProgressView to show that some activity is taken place and set the networkActivityIndicatorVisible.
Since all UI interaction happens on the main thread you could allow the user to delete multiple rows at the same time. Just send the request in the background and dont allow that user to swipe and delete that row until the operation is complete.
For a quick and dirty solution a UIAlertView would work. A more elegant solution would be some sort of view that drops down from the status bar with details or maybe add a button to the cell that when the user clicks on it gives them a reason why it fails. There are several solutions here.
I have an app based on a tab bar and data retrieved from the Internet. The main tab shows a map and one of the other tabs shows incidents around the center point of the map displayed using a UITableView. If the user moves the map and then moves to the incidents page, I need to refresh the list of incidents displayed in the table. To do this I request the incidents in viewWillAppear:animated: and when that completes (asynchronously) I call the table view's reloadData method.
This works beautifully unless the user taps between the tabs quickly (e.g. display incidents, move to map, move map, move back to incidents, move back to map, etc.). At some point the incidents data source (an NSArray) is modified while the table view is trying to access it.
Here is a question that is similar:
UITableView Crashes if Data Source Is Updated During Scrolling
One of the solutions for that question describes a solution at a high level that is exactly what I want: Freeze the data source while the table is being updated. The thing I can't figure out, however, is when to unfreeze the data source. The problem is I can't find any way to be notified when the table is done being updated.
Any ideas? How do I freeze the data source while the table is being updated and then unfreeze it once the table is done being updated?
Although I'd really like to receive a notification when the table view is done accessing the data source, I found that my problem was due to modifying the data container from the work thread. The answer to this question led me to the solution:
Refreshing XML data and updating a UITableView
What I do now is fill a separate array in the worker thread and then perform a selector on the main thread to swap the updated data into the data container used by the table view.
The problem is I can't find any way to
be notified when the table is done
being updated.
I think you can assume that the data is done being loaded by checking in tableView:cellForRowAtIndexPath: to see if the last row has been loaded.
I haven't tested it, just making an assumption based on the API
I'm currently looking for a way to provide the user with being able to select multiple items from a collection of values.
I know this is done in the mail app whereby you can go into the edit mode of a folder and select multiple items by clicking on the circle on the left hand side.
What I'm unsure about is how this is achievable. Is anyone familiar with how to reproduce such functionality?
Thanks,
Matt Delves
The easiest way is this:
Provide a UITableView with all values the user can select.
Keep a mutable array with one object (e.g. an NSNumber) per table row to store each row's selection state.
In tableView:didSelectRowAtIndexPath:, toggle the selection state in your array for the tapped row and set the tapped cell's accessory type to checkmark or none, depending on the selection state.
I have an application I'm working on, and I need the user to be able to add new "Shows", "Movements" and "Dots." These are all represented by classes. At the root of the application, all the shows are shown, the user can click on the show, see the movement in that show, then tap on a movement and see the dots in the movement. It works beautifully.
Now, I need the user to be able to add and edit these instances of these classes. The way I am thinking this will work is when the user clicks on the "Add Show" button (Or the "Add Movement", etc) a new view will be pushed onto the Navigation Controller. This works. When the button is pressed, a new instance of the show class is created, and passed to the new view controller. This also works. If the user wants to edit the show, then they will hit the edit button for the row, and the instance of the class (which already exists) will be passed to new view controller, and the user will be able to edit it (It should use the same view controller for adding and editing)
My question is, in the examples I have seen, it is always really dirty to create the editing view. The edit view is a table view with each row having some sort of control. Usually it is a UITextField, but it may be a slider, and it may be one where another view is popped, and the user needs to check one value. (This is similar to the address book application when adding and editing a contact)
Is there any way that is cleaner than just manually going in and creating a bunch of arrays to hold what custom table view cells need to be at what row? This gets very messy, very fast. I can do it this way, I just was wondering if there is a better, possibly faster way.
To my knowledge there's no structural solution to solve this. I'm afraid managing the cells with child UITextField or other controls yourself is the only method. This indeed gets dirty and painful very fast, I certainly feel your pain.
Although it doesn't exist, it would be very convenient if Apple added out of the box editing cells to the SDK, similar to the different normal cell styles. I haven't come across an open source project that addresses this issue, but it might exist.
If you do find a better/cleaner method to handle these situations, be sure to ping back.
as far as i know, editing mode is the only way to make the changes you describe (if i understood correctly). I agree that it doesn't seem like the most elegant approach.
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageInsertDeleteRow/ManageInsertDeleteRow.html#//apple_ref/doc/uid/TP40007451-CH10-SW19