keyboard hides text boxes in static table view - ios

Object C - iOS development. Hello all. I have a static table view with several text boxes to enter information. When I tap on a lower box, the keyboard hides the text box preventing entry of text. This app uses another static table view controller and when a lower text box is tapped, the view scrolls up allowing text to be entered, so it works fine. I must be missing a setting of some sort, but can't find it. Your help is greatly appreciated.

If you have a full screen table view controller by a subclass of UITableViewController then the keyboard interaction will be handled for you.
If you don't (you aren't using UITableViewController) then you need to do it yourself. Basically, you need to observe the keyboard notifications and use the keyboard frame they provide to you to change the table view frame so that it isn't below the keyboard.
See the docs for UIKeyboardDidShowNotification here. You might also like this project.

Related

How to implement newsfeed comment page similar to Facebook or Instagram

Both Instagram and Facebook allow their users to comment on news feeds. In the comment scene, they basically have a UITableView with all the comments and a “footer” where user may enter comments and post them. So the “footer” is a UIView or UIToolBar with a UITextField/UITextView and a UIButton. Truly simple stuff from the look of it. Well I have been trying to implement it and the keyboard is not cooperating. I need the keyboard to not hide the “footer”. Especially now in iOS 8 the keyboard comes with a suggestions tool bar that a user may choose to show or hide. All these interactions make it difficult to keep my “footer” right above the keyboard while user is entering text. Every time I think I nail the solution, I find a multitude of bugs.
In one implementation, I use keyboard notification to listen for when the keyboard is up or going down (partly based on iPhone Keyboard Covers UITextField). The problem with this implementation is that there is a lag of about 1 to 2 seconds for when the keyboard shows up and for the “footer” to climb to the top of the keyboard from the bottom of the screen. A second issue is when user drags the suggestion toolbar to either show or hide it while typing, it causes my “footer” to move in unpredictable manners: which means I will need some static variables to meticulously track cumulative interactions with the suggestion toolbar just to fix that bug. Also notice that I put “footer” within quotation marks. That’s because I am not referring to a UITableView footer. But rather a view that I create beneath the table view as suggested by UITableView, make footer stay at bottom of screen?
Another implementation I tried was to use a “footer” and a keyboard ToolBar. When user clicks on the UITextField of the footer, that would cause the keyboard to show up with a replica of the footer as inputAccessoryView. This is basically to visually fool the user into thinking it’s the same footer that seamlessly climbs with the keyboard. But in reality I am using two compound Views: a “footer” and a keyboard toolbar. The first problem I encounter with this one is that I cannot seem to make the tool bar text field the first responder programmatically. This actually used to work in ios-7. But since I updated to iOS-8 it does not work. So if I do footerTextField.inputAccessoryView=keyboardToolBar and then in the textfield delegate method check if(textField==footerTextField){[tooBarTextField becomeFirstResponder];}, iOS-8 just ignores the whole thing or, worse, dismiss the keyboard and the toolbar altogether, so that in fact the keyboard never shows up when I click on footerTextField since the showing and dismissing happen so quickly.So again this used to work in iOS-7, but in iOS-8 it does not work.
a third approach was to make the parent view a TPKeyboardAvoidingScrollView such that I would have parent, and children UITableView and “footer”. Here while TPKeyboardAvoiding have worked for me on other scenes in the app, for whatever reason it’s not working here. My guess is because I am using a UITableView as one of the children of a UIScrollView.
a forth approach was to make my “footer” an actual UITableView section footer; section footer because I want it to float at the bottom. The problem with section footer is that they don’t stick to the bottom, which gives a visually erratic user experience as you scroll the table.
Ok, so I have said a lot. So finally, has anyone implemented a scene similar to Facebook’s/Instagram’s NewsFeed Comment scene? If so, will you please help me?
To recap: the Facebook/Instagram input textfield grows with text; sticks to the top of the keyboard whether the keyboard's suggestion toolbar is showing or hidden; sticks to the bottom of the screen when the keyboard is gone.
SlackTextViewController seems to fit all your requirements and is very well-written.

Dealing with keyboard and tableviewcell

The layout for one of my View Controllers is such: I have a scroll view embedded inside my VC. Inside my scroll view, I have a table view that consists of 5 cell. The first 3 cells consist of a textfield thats pulls its text from a dictionary and this changes depending on certain situations. These textfields are editable and so tapping on them brings up the keyboard, the issue however is that I would like my view to scroll when I tap on the text field because right now they keyboard hides the the third editable text field. Another issue is that at the moment, clicking outside teh table view doesnt cause the keyboard to be dismissed and so the only way of dismissing the keyboard is tapping on the return key. What I would like to happen is that when I tap on either one of the 3 editable fields, the scroll view ought to scroll up a certain number that I define (this is so that I can define how much to scroll depending on which row is currently selected). One of the issues I'm facing is that I can't directly reference these textfields in my VC since they're all created through one prototype cell. My thinking was that I could create a dictionary with the 3 textfields as keys and then the scrollview y coordinates as values and then use that. However , I wasn't sure how to do this in my situation (with the prototype cells). Would really appreciate if someone could show me some sample code on how to do this.
You can reference your text fields by calling cellForRowAtIndexPath: to get the UITableViewCell, then calling viewWithTag: to get your UITextField. Just assign the text fields a tag number. Also, set the text field's delegate to be your view controller so that you can respond to a user tapping to edit text.

Adding buttons to static table view/calling methods from tableview cells

Quite simply, I'm trying to add multiple buttons to the bottom of the static table view, much like in the address book app (below the contact's details for Send Message, Share Contact and Add to Favourites). However it just simply won't let me add three button in Storyboards unless I use a subview but then I can't quite get the colour to be the same as that of the iOS 6 background (and I've used the colour picker). What happens is that it'll simply add the button below the table view section and it takes up the entire width of the iPad's screen.
My other (and original) thought was to use the static table view cells to simply call methods. What I want to do here is add the building's details (like address, name etc) to the user's contacts app when they press the tableview/button - but I can't link it to any IBActions.
Using a button would be no problem, so if the first issue could be solved that'd be excellent.
If you use the solution with the subview, you can set the views backgroundcolor to [UIColor clearColor]

edit the text of a cell?

I have a UITableView, and want to let users edit the text of a cell. I want to popup a new UIView to let them enter some text in textfield, then dismiss the view and replace the cell's label text. Is it possible?
This is kind of an advanced move, Vikas. The programming of and user interaction with table view cells is tricky. The reason is that the UI code is a bit tricky because of the scrollable view, and you have to be prepared for the table cells to move or change if the table data is reloaded.
Is there another way you can achieve the result you're looking for? Could you design your table view so that when a cell is selected, you push a new view onto the navigation stack, and have UI components on that view that enable the user to edit the value?
This is the way that Apple does the Settings on iOS. When you select a row, you are shown a new view that has appropriate editing or selection controls.
You should use the textLabel property.

How to use the UIPickerView on the iPad?

Using the UIPickerView on the iPhone is quite simple as it has the right size on the screen, however on the iPad it looks rather strange. I'm wondering how to display it in the best/most user-friendly way possible?
The purpose of the view is to display and edit meta data for an item. I won't need the full screen for it. The picker is used to determine the language the text is written in and is populated from a plist.
As I see it, there are four possibilities:
A full-screen view loaded by the parent view with the UIPickerView directly in it (looks weird)
A modal view which is slightly smaller to put over the parent view and a button to load the UIPickerView separately.
A UIPopoverController which has the same size as the UIPickerView, this will however cause problems with the amount of fields I need on the screen.
Same as 3 but with a button, as in the Calendar.app, which would save some space.
Did I miss something? What would you suggest?
What about a popover controller with your fields, wrapped into UINavigationController, and one of those fields navigates to another screen with just the UIPickerView? Kind of like the alarms are edited on the iPhone.
Also maybe UIPickerView is not the right tool to choose a language. What about just navigating to a list of languages with checkmark selection, not to a screen with a picker?

Resources