In my app I have a set number of cells in a UITableView, 10, no more, no less, and the user can't change that.
However what I would like to have is so that if the user was to naturally in an iOS fashion, swipe a cell, or press an edit button, the cell text becomes editable with a simple tap on the cell bringing up a keyboard.
I was just wondering if there is a fairly simple method to do this, or take quite of custom building? What are you thoughts on how this could go together?
Thanks.
This should work if you just add a UITextField into the table cell's contentView I believe.
Related
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.
I'm using storyboard to create a grouped UITableView. Within the table I have several different cells setup with the 'right detail' style. I have also added IBOutlets to the UILabels on the right of these cells, however when someone presses the cell there's no way of editing them.
Here is what the cells look like:
I need a way of allowing the user to edit the value on the right when they press the row in the table (similar to that of the 'Contacts' application on iPhone when you edit phone numbers etc.).
Please can someone help me?
A UILabel object does not support user editing. If you need a text field that the user can edit using the keyboard, you need to use a UITextField or a UITextView.
I am trying to implement editable cell in tableview, just like what is available in new contact screen in iphone and ipod
Right now I have two labels in a cell, one of which will remain same all the time and the other one will be editable. Do I need to change this label to textfield.
one more thing I also want that when i click one such cell it should pop a picker view and and set the picerview value.
#Umang in order to make your UITableView cells editable I suggest you to give UITextField to your cell....for more help how to do it take help from already asked How to make tableviewcell text editable on touch in iPhone SDK?
Yes you should add a UITextField to the cell if you want to editable. but
from your question i understand that you want to set a piker value to the cell label.
in this case you don't need to change the cell.
you should add the pop the picker in the didSelectRow method, and change the cell label to its result.
if you dont know how just ask and i will try to help.
Yeah, you will need to change it to a textfield. UILabel is non-editable by design.
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.
In my iPhone application I have used (UITableViewCellAccessoryCheckmark) to add the checkmarks in the cells, - it is added to the cell at the right side of the cell.
I want the checkmarks to display in the middle of the cell and after that a string should display. So that the user can set the cell item as checked or unchecked.
Please provide any solution or any code for adding the (UITableViewCellAccessoryCheckmark) in the middle of the cell.
There is no built in way to do this. You will have to create a cell, then in tableView:cellForRowAtIndexPath: you will need to either add a custom subview, or return a custom cell and tell it to display the custom checkmark you added based on the data state.
The accessory view of the cell is always on the right side, outside of the cell's content view (see the Table View Programming Guide for more on this). If you want to do something like this, you really need to create your own cell class, and draw the checks yourself.
Speaking as a user, this design seems sort of confusing, and definitely not what I'd expect. What's the string you're displaying to the right of the check? Maybe something like the UITableViewCellStyleValue1 style cell would work, instead? (See Standard Styles for Table-View Cells for more.)