iOS: cancel delete event UITAbleViewDelegate - iphone

I want to know the delegate method that gets called when the user cancel the delete operation of the UITableViewCell. Now to answer the potential question that "Why do I need this?", following is the scenario:
I have a table view where the item is displayed (which is left aligned to the main view) in a UILabel and its price is displayed in a separate UILabel (which is right aligned to the main view).
Now once the user presses the red (kind of no entry) button to delete any item, the whole cell is indented to the left and half of the price is clipped because of being out of the view. This looks quite ugly and hence I hide the price label upon press of this 'pre-delete' button (which works fine). But I want to display the price tag back when the user dismiss the delete button without deleting the cell. but I am unable to find the cancelDelete kind of event for tableview cell.
Thanx :-)

Here's something that might work instead, it stops the tableview from indenting the cells while editing:
Set UITableView's shouldIndentWhileEditing property to NO.
Implement the delegate-method tableView:editingStyleForRowAtIndexPath: method:
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
Or you can do this when you create your cells:
cell.shouldIndentWhileEditing = NO;
Hopefully this works for you.

Related

iPhone app: UITableViewController with UITextView in a cell, can't get rid of keyboard

I know this question has been asked before but I couldn't find an answer that applied to my problem.
I've got a UITableViewController that has a third row that is filled with a UITextView.
I'm quite happy with the way it looks and the way text is typed into it.
However I'm unable to find a way of getting rid of the keyboard once the user is done entering text. I'd like to be able to use the return button for actual \n in the text.
I've gotten this far that pressing the upper two rows will make the textView te resignFirstTransponder but is there a way to catch a tap on the greyish background?
This is all in a UITableViewController loaded from a nib file.
Btw, I'm quite new to iOS programming so the more elaborate your answer the better :)
Thanks!
A pattern many apps follow is to show a horizontal bar with buttons on it just above the keyboard. It can contain a done button clicking on which you can hide the keyboard. And of course you will have to create that horizontal view yourself.
Another way would be to enable a touch recognizer elsewhere, and on a tap outside hide the keyboard
One alternative would be to add a toolbar to the keyboard with something like a "done" button that will dismiss it. You can find some sample code about that here. One second approach would be to dismiss the keyboard when the user selects a different cell or even when the tableView scrolls. In order to do that, you can add relevant code in -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath or in -(void)scrollViewDidScroll:(UIScrollView *)scrollView respectively.
This can get a little tricky if your new at iOS. The way I handle a UITextView in a UITableViewCell is I make a custom UITableViewCell subclass with an outlet for the UITextView.
Then set your cell in interface builder to be of that subclass. In the CellForRowAtIndexPath:
set the delegate to self. Then in the DidSelectRowAtIndexPath you call the delegate for the TextView based on the indexPath, this way the keyBoard will dismiss for the correct row if you touch the background. If you want it to dismiss when the user touches any cell just call the delegate without specifying the indexPath. The Delegate is TextViewShouldEndEditing:.Ill post some code if you want.

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.....

Decrease UITableViewCell width and put custom button on the left

Is there any way to decrease the standard width of grouped UITableViewCell and put a custom button on the left side(outside of cell boundary)? I tried to change the cell size but it keeps same
You are going to have to fake the editing mode.
What I mean by that is that as AtomRiot said you have to subclass UITableViewCell so that when in editing mode you show the button you want on the left, outside the cell.
But first things first.
To change the indentation level for your cells all you need to do is implement this delegate method for the UITableView
- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath
So that takes care of it. Then in your UITableViewCell subclass all I would do is to implement the method
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
which I assume is called when the table the cell belongs to has changed to editing mode.
There I would fade in (or animate in any way you want) a button to appear on the left of your cell.
I have done it inside a grouped-style cell but never on the outside.
Give it a try!
You could subclass UITableCell and add your own custom views inside of it. I have not personally added a button inside one but it should work. It may get confused with the row selected call the tableview makes if you are implementing that.
The Cocoanetics blog seems to have a pretty good solution to this:
http://www.cocoanetics.com/2010/03/how-to-shrink-cells/

UITableView add new custom cell onto selected cell or another suggestion

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.