Delete cells in table view Iphone with edit button - iphone

I have a table view with different cells and basically I would like an edit button which would then make those red circle appear in each cell and be able to delete them. I already know how to make the "Edit" button appear and also I have overridden the commitEditingStyle method for the table view so I would like to know how to link the button to the action which trigers the red circle and how to make them appear and finally how to actually delete the cells thankyou :)

The editing style on your table view cells should be set to UITableViewCellEditingStyleDelete, and then you just need to make sure to call setEditing:animated: on your table view. UITableViewController can help provide a lot of this functionality pre-baked.

That's actually done through an undocumented API (though I'm not quite sure why) - using it would probably get your app rejected.
However, lots of apps simulate this functionality with their own code - you'd basically define a custom UITableViewCell subclass which changed its background color / toggled that extra red circle image when tapped, keep track of which cells had been tapped, and finally delete them all by calling deleteRowsAtIndexPaths: on the table with the collected list of rows.

Related

IPhone need design idea for tableview

i have a UITableView where i want one cell(database row) needs to be default,
So I am thinking of two options
in TableView upon clicking a cell, change accessoryType to mark just like ringtone selection in settings app
when user enters data, add an option (like radio button or segmented control) to make that cell (database row) as default one
I feel first option is good but we can implement code for that only in didSelectRowAtIndexPath but i need to jump to another view when user click on a cell.
So please give me an idea how to accomplish this
One idea iam thinking is adding an edit button but don't know whether its possible or not.
Thanks
Not sure if i understand your question correctly , but according to what i understand you want a table view in which many values will be there , and you want one value to be default which can be changed later.
According to me these ways would be pretty good,
Changing the accessorytype of the tableViewCell. (Most common way)
Changing the Highlighted property of the cell on loading the tableView.
Adding some image then setting the image as the background view of the selected cell.
Adding custom image view (such as tick or something and adding to the cell).
this code can be put in the viewDidload so your default selected value appears.
Hope this helps.
Don't know what you mean by default. I'm assuming you mean already selected. You might just want to set the accessoryType to the checkbox. That would be Apple's way of doing it.

iPhone Dev - Implementing checkmarks in a tableview that is in edit mode

I know how to use checkmarks in a tableview when it is not in edit mode. But once in edit mode, it seems that it won't allow me to add checkmarks. Any ideas how to get around this?
Detail accessories are pushed offscreen during editing. This is native behavior and unless you have a peculiar use case it's perfectly fine. If you are editing to sort by checked vs. unchecked, do that automatically. If you really need to, poke around in the methods of your table's delegate. Protocol reference.
Perhaps you can use the built in UIImageView that is on the cell so that when you are editing, if your table allows the editing of multiple rows, when the user taps the cell, the UIImageView is filled with the image of a check mark, but when the table is not in edit mode then the UIImageView is empty.
You can use the allowsMultipleSelectionDuringEditing property of UITableView to decide whether cells are selectable in editing mode.
Then calling indexPathsForSelectedRows will give you the indexPath of the rows the user has selected, and then perhaps you can have some logic to edit the cell's UIImageView property.
A bit hackey, but I hope this helps!

custom uitablviewcell does not call didSelectRowAtIndexPath in the controller

I have a custom UITableViewCell completely written in code (no IB), it has an accessory button that simply calls didSelectRowAtIndexPath on the table view, and it works correctly and the method is called without problems.
However, when I tap on the cell itself (not on the accessory view) nothing being called, why ?
EDIT: the code is huge to put here ... however, the custom cell contains a ton of labels, couple images and scroll view ...
This is a shot in the dark, but if each cell has many different objects on it (i.e. images, labels, etc) then it may not be working because those objects are what the user is hitting when they try to click a cell. Does the cell turn blue (indicate selection) at all? If not, try hiding/removing those objects for now and see if it works.
If that is the case, then what you may want to do is create an invisible cell or button that sits on top of the other objects and calls didSelectRowAtIndexPath from behind the scenes.
This should solve your problem:
Raise selection event (didSelectRowAtIndexPath) when subview of UITableViewCell is tapped
Try setting your view's userInteractionEnabled property to NO.
This will make it ignore all touch events, and then the views under it will be able to catch these events. - Felipe Sabino
I'd partially answer my question: the wide scroll view is preventing the cell from calling didSelectRowAtIndexPath, removing the scrollView will solve the problem, however, I want to call this method with the existence of the scrollView ... anyone got ideas would be highly appreciated ...
You must post your code to understand what have you done...You have to check out this example to understand whether your code is correct or not...
http://www.edumobile.org/iphone/iphone-programming-tutorials/impliment-a-custom-accessory-view-for-your-uitableview-in-iphone/

How to mark multiple UITableViewCells and perform an action on marked cells?

I would like to do pretty much what the Mail Application does: that when I select Edit, instead of the usual Delete Button, Radio Buttons appear on the side that may be checked by the user, then the user may click on a Button to take an action on the marked cells(any kind of action not just delete). Is there any apple sample code that does this?, can anyone please provide some code or documentation on how to do this?. Thank you.
-Oscar
I haven't done this so all of the following comes straight from the documentation. This is how I would do it:
Overwrite your view controller's setEditing:animated: method to display one or more buttons to execute your batch action (just like Mail.app does) when the table goes into editing mode.
Use a custom UITableViewCell subclass for your cells.
The key is to overwrite willTransitionToState: in your custom cell class. In this method, add a custom subview containing your radio button to the cell.
Overwrite layoutSubviews to position the radio button and the rest of the cell's content in the cell.
In tableView:didSelectRowAtIndexPath:, differentiate between the normal and editing states. If the table is in editing mode and the user taps a cell, mark it as selected (modify your radio button subview accordingly) and keep a record of all marked cells.
Here is a good article about doing a Mail-style multiple selection:
http://cocoawithlove.com/2009/01/multiple-row-selection-and-editing-in.html

Rearranging rows in uitableview

I've an application in which each row contains an uiimageview and an uibutton. I have created them using custom cells, uitableviewcells. The button is to trigger the method, uiimagepickercontroller to pick an image from the library and show it in the imageview. I need that any user who uses the application can rearrange the rows as they wish so that they decide the order of the photos. code here
Reordering of rows in a tableview is pretty straightforward, you just need to implement a few methods of the UITableViewDataSource Protocol and your good to go. Have a look at the Table View Programming Guide for info & code.
http://developer.apple.com/iphone/library/documentation/UserExperience/Conceptual/TableView_iPhone/ManageReorderRow/ManageReorderRow.html
You could show an Edit button in the navigation bar if your using a navigation controller, which switches the table view to edit mode, causing the reordering control to be shown. This edit button could be changed to done, once the table is in edit mode of course. Don't forget to set the showsReorderControl property of the cell to YES. From then on, it's just a matter of implementing the right methods.