UITableview Cell adding button in delete method - iphone

In my UITableview i have option for user to delete the row, i have done that but here i need to add a EDIT button with the DELETE button like the picture,
also when user clicks edit i want to allow the user to edit the ROW TEXT.. is it possible..?
Please help.

First of all you should ask yourself if you really need that edit button.
The user told you already that he wants to edit the tableView by tapping the edit button of the tableView. In my opinion there is absolutely no need for another edit button, the user will assume that everything he does in edit mode will edit the data.
There are two options:
Put the editing in another view controller that you push when the user taps the cell in edit mode.
For this you have to set the editingAccessoryType of the cell to UITableViewCellAccessoryDisclosureIndicator, to indicate that the cell can be selected.
And allowsSelectionDuringEditing of the tableView has to be set to YES.
Everything else is like handling row selections when not editing. Simply check for [tableView isEditing] in tableView:didSelectRowAtIndexPath:.
Replace the UILabel of your cell with a UITextField with a borderStyle of UITextBorderStyleNone and the same font as the UILabel. Set enabled to NO. This way it will look exactly like a UILabel.
Implement setEditing:animated: of the UITableViewController to enable each textField in editing mode
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
[super setEditing:editing animated:animated];
for (UITableViewCell *cell in [self.tableView visibleCells]) {
UITextField *tf = ...
tf.enabled = editing;
}
}
when the user taps the UITextField in edit mode he can input text.
If you really need that edit button add it in - (void)setEditing:(BOOL)editing animated:(BOOL)animated when editing is YES and remove it when editing is NO. Instead of adding and removing it I would just use setHidden:

Yes it is possible. You'll have to use the UITextField to show the text.
When user click on the Edit button you'll have to save the tag of the button. Save this tag so that you know which row is clicked. And then reload the table. While reloading the table make sure you set the userInterActionEnabled property of the UITextField at the particular row to true. It'll allow user to edit the text.

Create Custom cell and add your UIButtons and UITextField and just implement some logic. just refer tutorial from below links.
For Custom cell just see these below links with tutorials and demos:
custom-table-view-cells-in-ipad-programming
creating-custom-table-view-cell
Custom UITableViewCell in IB

Related

UITableView deselect selected cells after editing

I have multiple cells selected in a UITableView, but they automatically get deselected after editing. I searched a bit and I saw people saying that they called 'reloadData' which has caused the selections to be removed, but I do not call reloadData anywhere except for in 'viewDidAppear'. They get deselected even if the editing has been cancelled without changing anything (when clicking 'edit' button in the toolbar then clicking 'done' button without any editing). I'm not sure where this is happening. Or, if I could detect when the editing has been finished (when 'done' button has been clicked), I could simply reselect all the cells that had been selected, but I'm not sure how I could detect it..
How could I prevent the cells from getting deselected? Or reselect the cells after the edit?
Thanks in advance.
I presume you are trying to achieve selection and deselection on Button press, If you are trying to change the state of selection in a UITableViewCell try using the method in the button action.
-(IBAction) someAction {
if(buttonToggled){
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
}else{
//Do something
}
}
for changing the backgroundColor.
cell.selectionStyle = UITableViewCellSelectionStyleGray;
cell.selectedBackgroundView.backgroundColor=[UIColor blackColor];
for more information on the above please check the link.
UITableView Cell selected Color?
I would suggest the best bet is just to reselect them yourself after every press on your "done" button.
It is quite normal that cells get deselected or buttons get unpressed, since this is their normal state - exept if you write your own code to change this - like in your case.
This is how to select a row:
[tableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionNone];
If you have multiple rows that can be selected make sure you have the settings accordingly, otherwise it might always deselect all but the most recent rows.
Nevermind. I found out that - (void)setEditing:(BOOL)editing animated:(BOOL)animated gets called whenever the 'edit' or the 'done' button has been clicked.

How can I detect when the user has swiped an editable UITableViewCell?

I have an editable UITableView. By default the user can swipe and the Delete button will show up. I would like to hide some elements on my UITableView cell when this occurs. How can I do this?
Oh c'mon:
tableView:willBeginEditingRowAtIndexPath:
...
Discussion
This method is called when the user swipes horizontally across a row;
as a consequence, the table view sets its editing property to YES
(thereby entering editing mode) and displays a Delete button in the
row identified by indexPath. In this "swipe to delete" mode the
table view does not display any insertion, deletion, and reordering
controls. This method gives the delegate an opportunity to adjust the
application's user interface to editing mode. When the table exits
editing mode (for example, the user taps the Delete button), the table
view calls tableView:didEndEditingRowAtIndexPath:.
Reference
And then throw some [[cell viewWithTag:<#View's tag number#>] setHidden:YES] for your own views.
Try overriding the willTransitionToState method in your custom UITableViewCell. In particular you would be interested in the UITableViewCellStateShowingDeleteConfirmationMask state.
Couldn't you modify the pertinent elements of the – tableView:willBeginEditingRowAtIndexPath: is called?
As soon as the user wants to editing something in his tableView, this method gets called
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
if(editing){
// Entered Edit mode
// Show the new tableView and reload it.
}
else {
// End of edit mode
// Bring back the tableview and again reload it.
}
[super setEditing:editing animated:animated];
}
Update your UI in tableView:willBeginEditingRowAtIndexPath: and Restore in tableView:didEndEditingRowAtIndexPath:.

iPhone - changing contents of a UITableViewCell inside a navigationController

I have a UITableView with some cells in it that have people's names. When the user clicks on a cell, the Navigation Controller pushes a new view onto the stack that shows detailed info for that person. When the user is done and clicks the button to return to the previous view, the tableview is again shown. The problem is that I want to edit the cell text (or just mark the cell in some way) to show that the user has clicked on that cell. In my cellForRowAtIndexPath: method I have set up code that should change the text of the cell after a user clicks on that cell. I set up break points and it IS entering cellForRowAtIndexPath: when the detail view is popped and the tableview is again shown. It's entering the segment of code in cellForRowAtIndexPath: that should change the text, but when it comes up on screen, the text has not been changed. Does anyone have any ideas as to what is going on? Thanks.
EDIT: I figured it out. I just needed to call [tableView reloadData]; instead of calling the cellForRowAtIndexPath method. Not sure why that works differently, but it fixed it.
I guess I'll help you out. You don't need to credit me with the answer though.
cellForRowAtIndexPath:
that method is called within the framework when a cell is being refreshed from the queue or when it needs to be created. You should not call this method.
[tableView reloadData];
that method is basically a refresh on all of the visible cells show in the UITableView. This is the method you should call if you change information in your data source or you need to (force) update the appearance of your cells.
It's Good You Have Reload Table And Changed The Text But If YouJustIndicate NAd Don't Want To Change The Text The nYou Can Use elow Given Text ....
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
It Will Check Mark Particuler Cell Which You Click/Visited......
Hope You Like This Solution.....

remove UITableCell highlight

how do I remove the highlight color after a UITableCell has been selected? I am presenting a modal view over my uitableview and once that is closed the selection highlight is still there. I remember there is a simple setting somewhere but I cannot remember it.
The simplest way to deselect a cell is the -deselectRowAtIndexPath:animated: method.
To use it put this code in your Table View Delegate Method (tableView:didSelectRowAtIndexPath:):
[tableView deselectRowAtIndexPath:indexPath animated:YES];
You can change YES BOOL to NO if you don't want to deselect your cell with an animation.
The easiest solution would be to use the deselectRowAtIndexPath:animated: method on the UITableView.
See the UITableView class reference ("Managing Selections" section) for the the full method signature, etc.
Deselect cell using -deselectRowAtIndexPath:animated: method in selection handler
Also, if you don't know/care which cell is highlighted, and just want to deselect everything, you can use
[tableView selectRowAtIndexPath:nil animated:YES scrollPosition:UITableViewScrollPositionNone];

How do I prevent my table cell's textview from being editable after editing is done?

So this is an interesting problem. I have custom tableviewcells that include a text field. When In my cellForRowAtIndexPath I have an if statement that determines whether or not the cell's text field should be editable- it looks like this:
(self.isEditing) ? [infoCell.textField setEnabled:YES] : [infoCell.textField setEnabled:NO];
This actually works well - except for the issue I'm having. It makes it so that when the tableview is displayed, the rows' text field cannot be edited. When the user clicks "Edit" to put it into editing mode, then the text fields are enabled for editing.
The Problem: When I am editing a field, and click "Done", it goes back to the regular tableview but the keyboard stays visible and the last cell's text field I was editing continues to be editable.
What Should happen: The keyboard should go away and all the cells' text fields should no longer be editable.
Any ideas about what could be going wrong? Things to look for?
Thanks!
Unfortunately, disabling the UITextField won't dismiss the keyboard. You'll need to retain a pointer to your current UITextField. First, create an instance variable in your header file:
UITextField *currentTextField;
Then, implement the UITextFieldDelegate protocol. The dirty work will be done in the following method:
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
currentTextField = textField;
}
Finally, when you're ready to dismiss the keyboard and disable your textFields, simply call:
[currentTextField resignFirstResponder];
[textField1 setEnabled:NO];
[textField2 setEnabled:NO]; //ad nauseum
Good luck!
I've found self.isEditing to be unreliable. If you are editing an individual cell, it works differently from when you are in "edit mode".
What I've done to get around it is, whenever I want to do something to all other cells, I just iterate through my table view's visibleCells method and manually adjust them. You'll have to consider what happens when new cells become visible, but that's up to your implementation.
NSArray *visibleCells = [self.tableView visibleCells];
for (UITableViewCell *cell in visibleCells) {
[cell doSomething];
}
PS - obviously you may want to skip the cell in question when iterating through the visible squares. depends on what you're doing.