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

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

Related

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

Image Slider to my iPhone application

I need this kind of component to my iPhone Application. How could I Added to this to my project.
after i click that black color I need to animated it to left side and show next one.. like that
Try a tableView with one row and one section. Then the action of clicking on the row can trigger the delegate method of the tableView and use that to do whatever you like.
Alternately, you can make this a button with a custom view and swap out the view each time the user taps it.

Delete section (red delete button), UITableViewController - iOS

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.

How to change disclosure style when user enters in edit mode of a UITableView?

I have a UITableView that in 'normal' mode, show a UITableViewCellAccessoryDisclosureIndicator meaning if the user taps the row, another list is showed, like HIG says:
"Disclosure indicator. When this
element is present, users know they
can tap anywhere in the row to see the
next level in the hierarchy or the
choices associated with the list item.
Use a disclosure indicator in a row
when selecting the row results in the
display of another list. Don’t use a
disclosure indicator to reveal
detailed information about the list
item; instead, use a detail disclosure
button for this purpose."
When the user tap the edit button in the top bar of the UITableView, I think I have to change the disclosure because if the user tap it, a view for changing the information of the current row is showed (see the bold line above), again, like HIG says:
"Detail disclosure button. Users tap
this element to see detailed
information about the list item. (Note
that you can use this element in views
other than table views, to reveal
additional details about something;
see “Detail Disclosure Buttons” for
more information.)
In a table view, use a detail
disclosure button in a row to display
details about the list item. Note that
the detail disclosure button, unlike
the disclosure indicator, can perform
an action that is separate from the
selection of the row. For example, in
Phone Favorites, tapping the row
initiates a call to the contact;
tapping the detail disclosure button
in the row reveals more information
about the contact."
Have I miss understood the HIG, or I really do have to change the disclosure style in edit mode of UITableView? If yes, how I can intercept the edit mode when the user taps the Edit button?
Thanks in advance.
you do not need to manually change the disclosure indicator as the user switches in and out of edit mode. You can control what is displayed in edit mode by setting the "editingAccessoryType" property for the table cell. You would usually set that up in the tableView:cellForRowAtIndexPath method along with the "accessoryType" property which sets the disclosure indicator for the normal (non-editing) state.
From the table view programming guide:
accessoryType and accessoryView—Allows you to set one of the standard accessory views (disclosure indicator or detail disclosure control) or a custom accessory view for a cell in normal (non-editing) mode. For a custom view, you may provide any UIView object, such as a slider, a switch, or a custom view.
editingAccessoryType and editingAccessoryView—Allows you to set one of the standard accessory views (disclosure indicator or detail disclosure control) or a custom accessory view for a cell in editing mode. For a custom view, you may provide any UIView object, such as a slider, a switch, or a custom view. (These properties were introduced in iPhone OS 3.0.)

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