UITableViewCell and the case of the missing Subtitle - ios

I've checked all the usual suspects. I have a UITableView in an iOS 8 app that uses the UITableViewCellStyle.Subtitle and sets a subtitle for every cell. I won't bother including code as it's no different from any other code for this. The issue I'm having is best described as follows: my cells also have actions (the new API in iOS 8 lets you add actions to your cells accessible by swiping left on them, similar to Mail). Sometimes (seemingly random), however, the subtitles don't show up unless I swipe on them. Upon swiping, the subtitle appears. Scrolling the cell in and out of view again makes the subtitle disappear until I swipe on it once more. What could be causing this? The subtitle attribute is clearly being set on the cell, it just isn't visible when the cell becomes visible.
Additional info: when troubleshooting, I decided to disable the actions on the cell to see if that was the issue. However, the same problem would occur. Interestingly, with actions disabled, scrolling the cell out and back into view would cause the subtitle to appear.
I'm not unconvinced it's related to this: Subtitles of UITableViewCell won't update

You can chech my answer here for a temporary work around. Just put a blank space character in the interface builder inside the subtitle. check the answer for more details.

Related

Show and use drag/reorder-button on UITableViewCell without being in "edit"-mode?

I have a UITableView with a section where I'd like to show the drag/reorder-button depending on a setting from another section. I have implemented canMoveRowAt: and moveRowAt:to:, but the tableView only shows the drag-icon when tableView.isEditing = true.
I also need the ability to delete rows, but I want that functionality to only appear in edit-mode, so simply constantly being in edit-mode isn't any good for me.
I've tried playing around with the cell.showsReorderControl, but this also just hides and shows the button when in Edit-mode, and doesn't affect the cell in non-Edit mode.
Is there a way to show the reorder-button when not in Edit-mode?

Automatically scroll UITableView to show row **below** the row being edited

I have UITableView in a ViewController (not a UITableViewController) with UITextFields in each row. I would like the TableView to automatically scroll so that the row below the row being edited is always displayed. This allows the user to tap the next row to edit it. The built in iOS Reminders app has this behaviour.
I have followed Apple's advice on managing the keyboard but that only scrolls to show the row you are editing just above the keyboard, not the row below it.
I have tried adjusting the frame in scrollRectToVisible: but it makes no difference. In fact commenting out that line of code seems to have no effect at all.
It seems that the UITableView will always try to scroll to show the UITextfield being edited just above the keyboard, and I can't find a way of adjusting or overriding this behaviour so that it shows the row below it also.
Update:
I've found that the automatic scrolling behaviour can be prevented by overriding the private scrollTextFieldToVisible method of UITextField.
However, the automatic scrolling code provided by Apple in the linked documentation still does not work.
You can try setting setContentOffset property instead of scrollRectToVisible. like
[self->_scrollView setContentOffset:CGPointMake(0, textFieldRect.origin.y)];
Please follow the below link, it will make your work very easy.
Just add the files and make the tableview class name as "TPKeyboardAvoidingTableView"
https://github.com/michaeltyson/TPKeyboardAvoiding

Implement checkbox on UITableViewCell - Swift

I am building a ToDo List type app, and I would like to place an editable checkbox in each cell in the UITableView. I want the user to be able to mark the item as completed by tapping the checkbox in the tableView. They also need to be able to tap in the cell, outside of the checkbox, and segue to a detail view.
So far I have created a custom cell class. The plan was to display an image of an unchecked box, and when the user taps the image, the image is swapped with a different image of a checked box (and the item is updated appropriately).
I tried putting a Touch Gesture Recognizer on the image, but it didn't work. Whenever the image on the cell is tapped, it just segues to the detail view. Then I found an article somewhere that says to create UIView nested inside the cell and link the Touch Gesture to that. So I tried that, but now it only work intermittently. Sometimes it recognizes the touch correctly, and sometimes it just segues to the detail view.
I've seen this idea in the Wunderlist app.
How do I go about implementing this correctly?
iOS doesn't have a native checkbox control. Apple uses a UISwitch instead.
If you want to follow Apple's HIG, use a switch.
If you want a checkbox style instead, you have several options.
You can attach a gesture recognizer to an image view and do it that way.
You can create a custom subclass of UIButton (MyCheckbox).
You can find a third party checkbox class that somebody else already created. I would look on Cocoa Controls. A quick search reveals half-a-dozen different checkbox options.
An important thing is the size of the "hit box" that the user taps. You usually want to create an image/view that's at least 30x30 points in size, and 40x40 points is better. An easy way to do that is to create your checked and unchecked images with enough whitespace around them to make them 30x30 or 40x40 points.
My guess is that your image view is too small and that's why you report that it is only working intermittently.

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.

Giving a grouped UITableView "First Crack" at touches when using a section header view containing a control

I am using a standard grouped style UITableView that returns a custom header view for one of it's sections (using the tableView's delegate method viewForHeaderInSection:). The view that is returned for the section header contains a control. It displays an image and is a control so it can tapped to let the user change the image. My desired UI is similar to the photo for a contact in the Apple Contacts app (a floating imageView-like control in a grouped style table).
The problem I'd like to solve is that touches on the tableView section header go straight to the control. I'd like the table to get a chance to determine if the touch is actually the beginning of a scroll gesture. If not, then the table can pass the event to the section header view for processing.
This is how all the rows in the table behave since I have "delaysContentTouches" for the table on. I suspect the problem is because the section header view is not in the table's view hierarchy. So everything is probably working per spec. just not the way I want.
I want the section header view to behave regarding touches just like rows do (table gets first chance to process).
BTW I am not placing this control in a table row (which would solve the problem) because I want the rounded rect grouped style for all table rows, but not for this one UI element. This control is in the center of my table (header for section 1) which is why I want drags on it to scroll the table.
OK, so apparently this is simulator issue only. On a device my tableView gets the first chance at the event. So I guess I need to listen to the Apple mantra of "always test on an actual device" before posting to StackOverflow. Sorry friends... may my error be helpful to others who, like me, probably spend too much time in the simulator.

Resources