Delete section (red delete button), UITableViewController - iOS - iphone

I'm trying to do a grouped uitableview and I have activated the edit option. I want the user to be able to delete the whole section too, not only specific rows.
So, when you click EDIT, the red minus button that shows on the left of each table cell, should show up for sections (left of the section title) too.
Anyone knows a way to do this?
Thanks in advance to everyone!
Olsi.

There's no way to do it out of the box. You'll need to get fancy and return a custom view in your table view delegate's tableView:viewForHeaderInSection: method. When you enter edit mode, you'll have to add a delete button to those views.

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.

Hide some UITableViewCells when editing?

Background
I'm really struggling to work out how to handle editing mode of a UITableView and hide some rows in when editing commences.
I'm using a grouped table view style with multiple sections and multiple rows per section. The last row of each section is titled "Add new...".
The idea is to allow the end user to click the "Add new..." row within each section and then be taken to a new screen where they fill in some fields and then are returned to that tableview with their new row added within the relevant section. So the last row does not really relate to the datasource and is more of a UX thing.
I've managed to get the Add row appended to the end of each section.
The problem
I have a button that calls: tableView setEditing:animated: and this insets all the rows and adds a delete icon to the left of each row.
What I don't want to do is allow the user to delete the "Add new..." row. So my orignal thinking was to just remove the delete capability for those "Add new..." rows using the tableView:canEditRowAtIndexPath:.
This worked but looks really crap as all the rows are inset apart from the "Add new..." rows.
So my current thinking is when edit mode commences just remove the "Add" rows from the table view and then when editing mode finishes add them back again.
I tried to do this by traversing all the rows when the user clicked the edit button but it seems you can only get rows that are currently visible using cellForRowAtIndexPath:.
So I can remove the ones that are visible but as soon as the user scrolls down the tableview the add buttons are still there for the sections that were not visible (at the time editing was initialised).
Help!
Does anyone know how I can just hide the "Add" rows from each section when the user edits the table and then add them back after?
I'm looking for the same functionality that the contacts app uses when the user edits a contact.
Actually you did already close the answer, just use the method cellForRowAtIndexPath to pick up the cell you want to hide, and set its hidden property to YES. You make it!
Oh, I am sorry that I had not noticed you are using the group style, so my suggestion is that you can try to separate the add button to the others, like include it in a single section.
You can display a green (+) button on the "Add line" row so it lines up with the deletable rows.
Simply override -tableView:editingStyleForRowAtIndexPath: in your table view delegate and return UITableViewCellEditingStyleInsert for that row.
What about removing the Add line(s) from the actual data source and just calling [tableView reloadData] then when edit mode changes back, add them back into the data source and reloadData again.
return YES from canEditCellAtIndexPath for every cell in the section then in override
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {} and return UITableViewCellEditingStyleNone for the "add line" row else return UITableViewCellEditingStyleDelete

UITable View Insert Row - can I press the actual cell rather than the green plus?

My table view is set up such that pressing "edit" creates an insert row using UITableViewCellEditingStyleInsert. The cell reads "add new item" and has a green plus next to it.
When the user taps the green plus, a modal view controller pops up so they can add a new item. This is fine. But it only works if they press the green plus itself - not the "add new item" cell.
How can I make it so that pressing the cell itself will do the same as the green plus?
Thanks!
You can; you just have to handle the selection yourself. First set allowsSelectionDuringEditing = YES, as shown above, then in the delegate's didSelectRowAtIndexPath: method, check to see if the selected row is the last row (or whatever row has your plus icon). If it is, run the same code you do in the didCommitEditingStyle: method.
I think ,Not possible because the entire edit mode process of UITableView is controlled by iOS (done by private API's) not exposed to us. we do have delegated (UITableViewDelegate) functions but not sufficient to get your work done.
Although, we can show the selection on the table Cell while in edit mode.
#property(nonatomic) BOOL allowsSelectionDuringEditing
http://developer.apple.com/library/ios/#documentation/uikit/reference/UITableView_Class/Reference/Reference.html

Delete cells in table view Iphone with edit button

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.

Iphone: How can I make a grouped table NOT "move" when entering editing mode?

I have a grouped tableview with two sections, and I want the cells (in editing mode) to look like the "add stocks view" in the stocks application from Apple. I want the delete button to be positioned directly over the cells, and not to the left of the cells.
Any ideas on how to do this?
Try implementing tableView:shouldIndentWhileEditingRowAtIndexPath: in table delegate and return NO from it.