Creating a view for user to fill up a form - objective-c

I'm creating a view which provides some fields for the user to fill in - address, phone number etc.
I've seen apps that have populated fields with grey text like 'Fill in your name here' on the Name field, and when the user taps on it the text is gone, a keyboard appears and the view is zoomed in to the textfield(or whatever it is). Also, after filling up that field tapping the 'Next' button on the keyboard brings the user to the next field. I'm trying to do the same but I have no idea where to get sources on this. Pardon my poor googling skills ;p
Tried UITextView and UITextField but there isn't anything related to this on the Interface Builder. Figured it lies with the codes?
It'd be great if I can get some explanation or some links on how this works (: Thanks!
EDIT: okay I played around with the Interface Builder a lil more and realized I could set placeholder as the grey text.

It is in fact a UITextField.
You can get the greyed out text by setting its placeholder property.
I am not sure what you mean by zooming but usually they do use a scroll view or adjust the frame so that it isn't blocked by the keyboard.
The Next button is made available using a UIToolbar instance as the text field's inputAccessoryView. However the implementation is one's own and is not framework provided. You can look at this example to get started.

Related

NSPopUpButton in NSToolbar such annoying

Problem solved!:
Just check the "Unified Title And Toolbar" option of the NSWindow and the 1pixel-down problem goes away!
To change the toolbar height just select the Toolbar Item - Custom View and change size in the Size inspector.
==============================
If you know Xcode 5s layout than you should recognise this:
I want to build it for my own. So I dragged a Toolbar in the Window and added a NSPopUpButton. Then I changed the PopUp Button Cell Style to Radio and turned off the Arrows. So far so good.
The first thing I noticed is that the Toolbars has different heights. Does anybody know how to change this behaviour (without subclassing NSToolbar)?
The second and more annoying thing I noticed is that if I choose an Item from the PopUp Button the Image for the NSMenuItem move 1 pixel down.
EDIT: Xcode NSMenuItems don't move 1pixel down
Any suggestions about that thing?
NSToolbar, sadly, can’t really be subclassed. It’s a poorly-written class that tries to be very “magic,” so it’s not even a subclass of NSView—you can’t control how it draws at all, it creates a private view.
You can set its “sizeMode” but I assume you’ve already done that and found that the number of pixels high isn’t what you want.
The easiest thing to do is just leave space for your widgets at the top of your window (above the document content) and have autolayout position your buttons for you. (I haven’t been able to use a real NSToolbar in years because of its limitations.)
As for the popUp menu being mis-aligned with the button: where the menu draws is basically hard-coded, so if you use a button style that NSPopUpButton doesn't expect then the menu will be offset some.
If you’ve already tried just unchecking the “draws border” flag on a default-style NSPopUpButton (one fresh off the palette), There are two solutions for to try: One is to keep trying different buttonStyles that look correct to your eye until you find one that’s not offset. Two is to leave the buttonStyle do the default for NSPopUpButtons but subclass the buttonCell and have it not draw the border (but still leave room for it).

UTextView autocomplete vs live suggestions iOS

If I turn the autocorrection ON, the words get autocompleted, as if I write "wor", I get "word" before I finish writing. I don't want this to happen because I might be writing "world" or any word different than the autocompleted one.
I set Correction off in the Interface Builder and this problem is solved.
The problem now is that I still need the suggestions that appear in a little popover below the incomplete words.
This two features might be different but I don't know how to activate the suggestions.
How can I solve this?
This can be solved with the use of tableview. Create a tableview with the width as of the width of the textfield and height as you like. Place it just below the textfield. Make it hidden initially. When the user starts typing, fetch the array of data that resembles to the typed text and if any exists then, unhide the table view. On the subsequent typing keep on reloading the tableview sections with animations. You should be accurate on hiding, unhiding and then reloading the data on the tableview. I have implemented such thing before. It is really easy and once you get started with it you find it easy.
In the UITextView TextViewDidChange I created a thread that changed the cursor position. This, off course happens after the text view changes. The change of the cursor position triggers the autocomplete without letting me even see that there had been a suggestion.

Editable text inside UISegmentedController

I want to have a UISegmentedController but the user can choose the segment and change the text inside. Is there any way to do that?
Thanks.
EDIT: This is what I would like to do. I have users which choose an option using UISegmentedControl. Under settings, I would like to give them the opportunity to modify what the texts in the UISegmentedControl is. I can use a UITextField and a button which triggers the change but I didn't like that solution. I considered putting a UISegmentedControl image with UITextField inside each segment but that does not seem like an elegant solution. Besides, I have no idea what the font is being used in UISegmentedControl. If I am not mistaken, by default, you can only fit a maximum of 12/13 chars or else it can break. iOS 5 SDK has some more methods to customize so it may be possible.
I coded a solution which involves a preview of what the UISegmentedControl will look like, 2 textfields to replace the texts inside each segment and a button which saves the value. I scraped it because I did not like the implementation and I just didn't like the execution too. I wanted the users to feel like they are using the UISegmentedControl and able to edit the texts inside it, up to a max of 12/13 chars.
Thanks.
You can always dynamically change the values of the segmented controller in code. Would it be acceptable to have the user click the button, at which point you could pop up a form for the user to fill in with the new value, and then call this method on the segmented control:
- (void)setTitle:(NSString *)title forSegmentAtIndex:(NSUInteger)segment

iOS Longpress to select text

I am building a simple table based search app. The user can ofcourse search through keyboard. But I also want to have another mode of search.
Say a user longpress on a UILabel then based on where the press is happening, that word should get selected & search should happen (no keyboard) on that word.
I know how to detect longpress events but does anyone know how to copy, detect & access the exact term where the longpress has occurred?
UPDATE: I am aware that I can get the object where longpress occurred from which I can get the content of the label text. But I need the exact word on top of which the finger was placed.
Nothing easy comes to mind for UILabel or UITextView. If you're wiling to lay the text out yourself with Core Text, then you can pretty easily find words near the touch. The trouble with that is you'd lose the existing selection features of UILabel and have to reimplement them (or do "shadow layout" in Core Text hoping things will lay out identically in the UILabel... slowly descending into madness here.)
Rather than going down this rabbit hole, I'd recommend using the standard text selection mechanism and add "search" to the menu.
Just put a UILongPressGestureRecognizer on your label then when the gesture recognizer fires you can access which object it came from and read the label value from there.
myLongPressRecognizer.view

Interface Builder won't allow drag/drop of text control to window

Noob dumb question, no doubt -- but here it is:
Trying to tutorialize myself with the Apple "Currency Converter" tutorial for Cocoa ( http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ObjCTutorial/05View/05View.html)
Embarrassingly, I'm stuck very early on where the instructions ask me to drag-and-drop a text field onto the Currency Converter window. When attempting to do so, I release the mouse and the text field runs animatedly back to the library palette, refusing to "stick" on the client area of the Window.
Clearly the window is readonly or lacks some state or prerequisite to accept the text field, but what?
Are you sure you're dragging a view object and not a cell? Double check that you're dragging NSTextField and not NSTextCell.
Be sure you're not grabbing a text CELL.
When you select the text field from the Library, check that the description is NSTextField
Have you added a view to the window? Because if there is no view then you won't be able to add any controls.
Drag a "View" object over to your window.