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
Related
I have a scrollview which has several table views as sub views...
say that I have selected a cell in one of the sub views. Now when I select a cell from another view, the cell I selected previously should not be highlighted.
How do I do this? I know I can do this using the first responder, but I am not sure how to do it.
Would anyone be able to help me out in this?
Thanks
From the apple interface guidlines:
Always provide feedback when users select a list item. Users expect a table row to highlight briefly when they tap a selectable item in it. After tapping, users expect an immediate action to occur: Either a new view appears or the row displays a checkmark to indicate that the item has been selected or enabled.
In rare cases, a row might remain highlighted when secondary details or controls related to the row item are displayed in the same screen. However, this is not encouraged because it is difficult to display simultaneously a list of choices, a selected item, and related details or controls without creating an uncomfortably crowded layout.
I don't think apple will approve an app that leaves a row highlighted (I had an app reject for that very reason). You should perform an action and then immediately unhighlight it. In some rare cases you can leave it highlighted while showing a related view.
However, if you store the current cell you have selected, you can call -deselectRowAtIndexPath:animated: on the tableview to deselect a row.
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
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.
I am newbie to iphone programming. I doing an mail like app in that i have to show inbox information in table view and at the final of dragging i should need "show 20 more messages" button. is there possibility of showing that?
if please can you provide with me a codes.
Regards,
sathish
Sure, you just have to manage it manually:
Add one extra row to your table view.
In tableView:cellForRowAtIndexPath:, if the indexPath corresponds to the last possible row (which is the extra row you added), create a cell that represents the button.
In tableView:didSelectRowAtIndexPath:, if the indexPath corresponds to the last possible row, have your datasource load the additional data and send a insertRowsAtIndexPaths:withRowAnimation: to your table view.
I'm really confused about that;
I have an example view. it contains an UITableview, this tableview contains approximately four or five rows. I don't know am i right or wrong way ? I'm trying that when the user click to the cell the table, i'm trying to add new custom cell onto the clicked cell with animation, this custom cell contains some action and information about the clicked cell. This is actually like to FaceBook start page on the iphone. In Facebook program when the user click to plus icon on the left side of row on start page view, it's working but how.
Can someone provide me an example code or any suggestions ?
Thank you very much.
EDIT :
Guys let me add more detail with some screenshots.
alt text http://img24.imageshack.us/img24/8159/img0398.png
As you can see on this picture, displaying list of data or some think like that.
When the user press the talk balloon (with plus icon) on the right side or per row.
alt text http://img682.imageshack.us/img682/1726/img0399.png
Custom cell or view (whatever) is coming from leftside to onto the selected cell,
with transition.
I think, my question was very clear now.
How can i do that ?
To show plus button in the cell you must set table view's editing property to YES and implement delegate's editingStyleForRowAtIndexPath method - return UITableViewCellEditingStyleInsert for the cell you need.
To add the new cell (with animation) to the table view you must implement
(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
in your datasource - make necessary changes in your data source (the number of rows in table must be increased by one after this method) and call
- (void)insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation for your tableview to animate changes.