Input view for textfields in table view - iphone

I Have an UITableView with textfields in each row.
I want to access these textfields each in a different way like adding a picker view for one textfield, navigating to another view when clicked on one text field.
i know how to do it when these textfields are in a normalview but i never have done it before on tableview.
Please help.

Your question is where to put the code to handle user interaction with your table view cells. Well the proper place to do that is the didSelectRowAtIndexPath: method of your table view controller.
However, there are a few caveats.
You need to add the UITextFieldDelegate protocol to your table view controller.
You can distinguish between the active UITextFields with tags, as suggested in other answers.
However, recycling the cells can lead to big confusion about the text fields. So make sure you update that id tag in the part of cellForRowAtIndexPath: that is not creating new cells.
You should not use a UITextField when you want another controller to pop up. In this case, just use a UILabel or the provided textLabel property of UITableViewCell. Push another controller when the user selects the row.
Only use a UITextField if you want the keyboard to pop up without leaving the table view.

And one more thing while assigning tag to text field, don't forgot to this line
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:nil] autorelease];

i think you need to give tag to each textfield like
textfield.tag = indexpath.row;
according to tag you can move ahead...

Related

How to insert button into Table view cell Swift

How do add button on each cell for table view cell so that it know which one is from.
Example:
Data have 2 products which is product A and product B, then I store them in array which is [product]. Inside the array, there have their detail which are name and price. So, I have successful making these into the table view.
The Question is how to insert button into the table view cell?
Example:
When button pressed, it know which row is pressed which is when press the 2nd row will be product B.
I'm newbie here. Need help, thanks.
You have two options:
Option one - easy, quick, bad:
create instance of the UIButton with the frame to position where you actually want the button to be placed. add tag property as well as the action. Action would be the same for the each button and you could use that tag to do the different actions.
Option two:
Create subclass of your UITableViewCell. Add all the element you want there. Create action for the button and you can set the target UITableViewCell or UITableViewController. If you choose UITableViewCell to be the target you will have to implement delegate, confront that delegate in the UITableViewController and implement that delegate function there. If you choose controller to be the target, you will have to send it to the cell. You will have to set tag as well.
I would use option two because it is scalable, easly maintained, and you have visual of the cell. Adding more components is easier as well.
I don't thing you need to put button or any other control in UITableViewCell to identify the selected cell.
All you need to do, is to implement following delegate method in to your class where you have implemented UITableView
tableView(_:willSelectRowAtIndexPath:)
tableView(_:didSelectRowAtIndexPath:)
and these methods will let you know selected UITableViewCell indexPath and you can do what you want to do on selection.
Note: do not forget to set your UIViewController as delegate to UITableView (almost like you did in case of DataSource).
Here's a Github repo you can refer, the code is not in good shape though.

Custom UITableViewCell with Storyboard

My goal is to create a custom UITableViewCell which contains 2 UILabels. One is the title and one is the detail. The detail label should allow for 3 rows of text.
So I went on and created a custom table view cell in storyboard. I also created a subclass of UITableViewCell and linked the two together.
I the added two UILabel to the cell in storyboard and placed them where i wanted them to be and linked them to their coresponding outlets in teh subclass. Since the content of the labels varies I wanted to align the text vertically to the top. As I understand the only way to do this is by calling the sizeToFit method on the label. I execute this under in the sub class of UITableViewCell:
-(void)layoutSubviews {
[super layoutSubviews];
[self.detailTextLabel sizeToFit];
}
So far everything seems fine and the text in the detailTextLabel is aligned as it should. Although when i satrt interacting with the cell, for example slide my finger over it so the delete button appears, the detailTextLabel will change size to the size that was set in storyboard. This causes the text to be misaligned. Similar things happen when i select the cell and change to another view and the return to the table view via a tab bar
My question is: Is there any way of creating this custom cell differently using storyboard or is my only alterative to create everything programtically?
Regard, Christian
Maybe you should take a look at this if you still want to vertically align your text in your UILabel without sizeToFit (who will resize it when you will interact with your cell).
About your question, I think you can create your custom cell from a xib file like this.

Adding a uiview in TableviewCell

I have a UITableView with custom cell. I have created seperate class with xib for the tableviewcell. in tableviewcell i have added a UIView, because i want to add different uiviews in the tableview.
Now I have 2 views which i want to add based on my data to the tableviewcell. i,e; if my data support view1, then i am adding view1 in an array which will be used to draw the table view & in table view drawing i am simply writing like this:
cell.parentView = [dailyExpenseViewArray objectAtIndex:indexPath.row];
Daily Expense View array is an array of views of type 1 & 2. Parent view is the UIview object inside tableviewcell.
My problem is i am having the view array perfectly. but in the tableview, it is showing blank rows. although the number of rows are drawn, but with blank views.
Any help would be appreciated. Thanks in advance.
I'm not sure I fully understand your problem without seeing some more code, however I think it may be an issue with the way you're trying to display the UIView inside the cell. Have you tried the following:
[cell addSubview:[dailyExpenseViewArray objectAtIndex:indexPath.row]];
It is not fully clear what you are trying to do, possibly some code would help.
Anyway, if I am understanding correctly, I would suggest trying to add your views as subview to the contentView property of your cell (instead of setting parent, I mean), like this:
cell.contentView = [dailyExpenseViewArray objectAtIndex:indexPath.row];
hope it helps...

Allow input in a UITableViewCell

So I have a UITableView (its in a UIPopOverController if that matters), and I want the user to be able to edit the content of the tableView. I added a UINaviagationController, the tableView also has a title and an edit button. Essentially what I'm asking is, when the user taps the edit button, how can I add like UITextViews to some of the tableViews and in one of the cells, a UISegmentControl and a UITextView.
Thanks in advance
just add them as subviews of the cell, set correct frame to make subviews inside the cell

iPhone next UITextField

I have an application with a UITableView with grouped style. On each of the cells, there is a UILabel with a description, and a UITextField for the user to enter data.
We implemented a toolbar on top of the keyboard, with next and prev buttons (similar to what MobileSafari provides when filling forms). In order to give focus to the next field, we resorted to using the tag attribute with consecutive numbers, and we find the subview by tag.
We can't use the responder chain because all the textfields have a different parent view (their UITableViewCell).
However, when using the iPhone Simulator, the Tab key on the keyboard (and Shift-Tab) work as expected and will move the focus to the next or prev textfield, regardless on where it is in the view hierarchy. After seeing that, we are sure there must be an API that provides us the required functionality, but we could not find it. Any hints?
I'm not sure exactly what functionality you are trying to implement.
However, I suspect it will be of interest to you that you can access the controller from the cells as follows:
UITableView *myTableView = (UITableView *)self.superview;
NSIndexPath *indexPath = [myTableView indexPathForCell: self];
MyTableViewController *myTableViewController = (MyTableViewController *)(myTableView.delegate);
Once you have messaged the controller, it in turn can access whatever cell is desired with cellForRowAtIndexPath.