I am currently working on a settings page for my app. I am using static table views to setup the UI of the view. My problem is my input handling - i cannot find a structured way of changing the input methods from every cell and saving it.
For example, i have a gender input where i use UIPickerView and i then have a age- and weight input where i use UIDatePickers configured as valuepickers. How do i program these different input methods in a way, that they are structured.
My current thoughts are using a hidden UITextfield to show the input methods and altering as the user touches different cells - but i don't know it that would be correct.
Any help would be much appreciated.
I assume you use UILabels to display input values in UI. If you do, you could replace them with UITextFields to which you assign your pickers as inputViews and then when cell is tapped you call tappedTextField.becomeFirstResponder(). After picker is resigned you update tappedTextField's text value.
Related
This is more of a question of how to go about achieving it rather than a specific solution. I would like to have a label which allowed buttons and textfields to be inline and wrap to the next line. An example is the iOS shortcuts app where you can type in the same block as the text, and the textfield wraps along the same line. It is a textfield as there is a caret.
At a highlevel it might look something like this:
where each view follows the line and wraps to the next when needed.
I originally thought about using an NSAttributedString with links that were styled and the link could either act as a button, or open a textfield for input. I tried this and got something which worked but it did not resemble the iOS shortcuts app where the textfield is within the text. I have also thought about using textkit, but I have not gotten that far with this as I am not sure it is the correct approach.
Thank you for any ideas or solutions.
EDIT
I have thought about another way of achieving this but I don't know whether it would work either. The idea would be to use a collectionView of textfields. Some textfields would share the same LayoutManager so that the text is shared across the textfields. I would have to calculate how many textfields to create so that they flowed down the collectionView
In the image, Label 1 is made up of 1 textfield which has editing disabled. TextField 1 is made up of 3 textfields which have editing enabled and the three textfields would share the same LayoutManager. Label 2 is made up of 2 textfields with a shared layout manager, but editing disabled.
Using this approach would mean calculating how many textfields to create for each "Block" (Label or TextField) and updating this each time content changes. With this approach, I am only thinking of labels and textfields but the button can be added at another time.
I just started on this, but realised that sharing layout managers disables editing so I don't know whether this would be possible anymore.
Thanks
This is non trivial task for sure, and I don't think there's a ready-for-use solution.
Using NSLayoutManager you can calculate frames of each line/character of your text, and then forbid touches depending on these frames, and add background under editable text.
You have to use UITextView, because you gonna need to forbid user to select part of the text, and you can do it using something like willChangeSelectionFromCharacterRange:toCharacterRange: delegate method, and ofc you need shouldChangeTextIn: to forbid removing non editable text too.
I have a module to be developed where i need to tab on my form textfields using bluetooth keyboard. But it doesn't seem to work. the method textfieldshouldbeginEditing gets called multiple times as many times as the number of text fields on the xib. Can you please help as to how to change the responder once i get the tag of selected field. I have my text fields in an array. tried using that but it continuously loops in that method.
Dealing with tabs within your views is a non-trivial task. At a high level, UIKit will check every visible field within the view once to determine which fields could be tabbed into, then it will check the "next" field a second time. You will need to keep track of which fields have been checked, and what order you want the tab to proceed in if you want to deal with this issue.
Please see this blog post for a great explanation.
I am building a part of my app that uses a Dynamic TableView with a UITableViewCell class with 1 label and two UITextFields. One textfield is for the user to type a question and the other is for them to type an answer. The goal is to save the text from the two text fields into CoreData. I am however unsure how to correctly identify one textfield from another since there may be 4 or 5 rows with the same text fields in the table.
I've attached a screen shot of what it looks like.
Should I be using tags on each textfield? If so, how can I set that up?
Thanks for the help!
I'm not sure your exact setup, but it seems easiest to use tags.
When you set the placeholder text for each "He said/I said," also add a line textField.tag = <uniqueTag> where you (arbitrarily) come up with a unique tag for each UITextField that you have. Then, when the user hits save, or when you get a call to a delegate method for all of these text fields, you can differentiate them by checking their tag property.
I need to be able to disable the keypad in a textfield, and instead when the user taps on it to start editing, a new table view will appear presenting a list of possible strings with which the textfield should be filled.
Anyone has any suggestions on how to achieve this?
Thanks in advance
p.s. I tried already but this functionality cannot be nicely implemented with a picker in my case, as there are too many options to choose from and (more importantly) each one of them is a rather long string and cannot appear entirely in a picker.
I believe you just need a regular cell that, when tapped, pushes a new detail UITableViewController with all the options to choose from. Once an option is chosen, set the cell's textLabel to whatever option have been selected.
If you'd like to go for an easier path, then you should also probably check the free Sensible TableView framework, as it has these kinds of cells out of the box (called selection cells). You just pass on your strings array to the selection cell and it will automatically display the detail view, and even assign the selected option to one of your object's properties if you wish. Should save you some good amount of manual work. Good luck!
having a bit of panic and really really need some help with this!
I'm making an app to fill in forms. The layout of the forms are created on a web server, and then the ipad app syncs with it, copies the form database, and then runs it locally.
One type of text field is a UITextView where the user can input text either by writing directly to the field, or by using one of many pre-defined texts (also defined on the web server).
To use a pre-defined text, the user touches/selects the tablecell that is containing the UITextView, and then a category-picker-view is pushed on the screen. On selection of category, the user gets a list of texts, and upon selection of text, the user gets a simple uitextview to edit it before insert. With a save button, the user then gets moved back to the original view where the chosen text is now added.
Flowchart:
root view with input fields-> category picker -> text picker -> editor
/\ |
'------------------------------save text------------------------'
The problem is that when any other view loads, all other input fields are emptied! The value of the selected field is passed via prepareForSegue, so that one is kept.
I have a save function which saves all fields to the database. I tried to put a call for it inside the prepareforsegue call, but it either crashes or does nothing.
Question: Where could i put the save function? Could/should I do it another way? Thought about putting all tag's values in a dictionary inside my appDelegate instead of running the save-function, but how could i update it every time an input field is edited?
Also - would putting the categorypicker etc in some kind of popover/modal/popup-view instead of the push segue prevent the values from clearing? I've got no experience from such views, could someone give a good starting point? (perhaps a good tutorial rather than heavy apple docs :)
I have a deadline for this tomorrow, with LOADS of more things to complete as well, so I'm very very grateful for ANY help!!
Thank you for your time!!
/Dave
I think your problem is caused by an absence of a model (in terms of the model-view-controller pattern). A model that represents your form data (e.g., custom object, NSArray, NSDictionary) should be updating the view and should be passed in prepareForSegue, not an input field's value.
Specifically, create a new property that maintains the latest data. When the user makes an edit or selects a category for some field, update the model. Then, when you return to your form view controller, use viewDidAppear to update the input fields to their latest values.