If one were to create a standard grouped table view consisting of two rows and then touch down on the first row, the cell would highlight. If one were to then drag one's finger down, the selection of the row cancels, and the table view begins to move with the drag.
Imagine the same situation, but with table view scrolling disabled via tableView.scrollEnabled = NO. Now, when one has selected a row and begins to drag, the row deselects and the table remains static.
I have two questions:
How can I ensure the row isn't deselected when one selects and drags within the confines of the row?
When one drags from the first row to the second row, how can I ensure that the first row is deselected and the second row becomes selected?
For an example of this functionality in action, open the Clock app and select the Alarm tab bar item. Tap the top right plus button and a modal view will appear presenting four rows. Tap down on the first row, drag onto the second, and you'll see the selection move across rows while the table itself remains static. How is this achieved?
On a tableView with scrollEnabled = NO when you touch on any cell you get a didHighlightRowAtIndexPath, and when you start to drag you get didUnhighlightRowAtIndexPath (even if you stay within the cell). The cell is not selected or deselected when you drag, and no further cells highlight/unhighlight on that touch.
There is a shouldHighlighRowAtIndexPath method that is called, where you can decide if the touch should highlight the row or not, but not a shouldUnhighlight method.
If the 'flash' of the highlight/unhighlight bothers you, you could use the shouldHighlight method to just return NO. Or you could return NO if a cell is selected.
Related
I have a GWT CellTable contained in a ScrollPanel. The CellTable is set to use a SingleSelectionModel<T> I am programatically setting the selected row, which is working fine. However, the cell table isn't scrolled to the selected row. Is there a way I can both select the row and scroll so the selected row is visible?
Andrei was on the right track, but setScrollTop(int) gives the number of pixels to scroll, not the index to scroll to. What works is:
myTable.getRowElement(index).scrollIntoView();
this adjusts the scrolling so that the element is in view. Note that if your table scrolls horizontally, scrollIntoView() will scroll it all the way to the right in an attempt to show all of the cell. I didn't want this behavior, so I subsequently called:
myScrollViewThatContainsCellTable.scrollToLeft();
Try
myTable.getRowElement(index).setScrollTop(0);
where index is the index of a selected row.
I have a group table view with 10 sections, each section has one cell, and each cell has a text field inside.
When user tap on a text field I scroll its parent cell to bottom, so that it will be exactly above the keyboard.
Every text field has a "Next" return key, so when user tap it the next text field (in the cell below) should be first responder.
The problem is:
Suppose user tap on a text field of cell at index 5, this will make the keyboard pop up and the tableview will scroll so this cell will be right above the keyboard.
Now user press the next button..
What I want to happen is to make the text field of cell at index 6 become the first responder.
But how do I get this text field??
If I try to get the cell with cellForRowAtIndexPath I'll get nil, because the cell is invisible..
Two solutions come to mind:
1) you don't have many cells, so don't recycle them, create them when you startup and put them in an array where you can easily get them, Then, when the tablview asks for cells, you pull them out of your array.
When you want to go to next, you simultaneously tell the tableview to scroll to such and such a location or cell, and you pull the cell out of the array, add it to your view with some offscreen frame so it cannot be seen, and make the textField the first responder (to keep the keyboard up). when the tableView asks for the cell, you MAY need to reset the frame, or both reset the frame and remove it from the view. If you find you need to do this you MAY need to make it the first responder again soon (dispatch a block to the main queue so that the text field never resigns first responder.
2) Similarly, when you want to make a cell's textField the first responder, and its contained in the visible cells, then you can just scroll and make it the first responder. If its not in the visibleCells, create a cell, add it to the view as above, do the first responder stuff as above, and when you are asked for THAT cell's index, supply that cell, possibly resetting the frame.
I've used offscreen textFields to play tricks with the keyboard (to keep it up, to get it up, etc - so I know that works). What's less certain to me are the tricks with the textField being in the view or not.
This makes me think of a 3rd way. You put a UITextField offscreen in the view. When you want to switch, and the cell is not yet visible (that is, created), you tell the offscreen textField to be firstReponder, then track the tableView scrolling, and when it ends the textField you WANT s first responder is now visible, so you can transfer (ie set) firstResponder on it, keeping the keyboard up.
I do not know how you create your rows but you need to consider, that UITableView recycles the cells. That means that the text field could be theoretically the same as before, just the content changes.
So all you need to do is make sure you know the textfield that is positioned right above the keyboard. I would not be surprised if this will be created when the view enters and never actually changes.
Again, the table recycles the cells and their content holders only filling in the corresponding data for the row as you provide it.
If you post your code that creates and recycles the cells I could be more specific.
I have a scrollview which has several table views as sub views...
say that I have selected a cell in one of the sub views. Now when I select a cell from another view, the cell I selected previously should not be highlighted.
How do I do this? I know I can do this using the first responder, but I am not sure how to do it.
Would anyone be able to help me out in this?
Thanks
From the apple interface guidlines:
Always provide feedback when users select a list item. Users expect a table row to highlight briefly when they tap a selectable item in it. After tapping, users expect an immediate action to occur: Either a new view appears or the row displays a checkmark to indicate that the item has been selected or enabled.
In rare cases, a row might remain highlighted when secondary details or controls related to the row item are displayed in the same screen. However, this is not encouraged because it is difficult to display simultaneously a list of choices, a selected item, and related details or controls without creating an uncomfortably crowded layout.
I don't think apple will approve an app that leaves a row highlighted (I had an app reject for that very reason). You should perform an action and then immediately unhighlight it. In some rare cases you can leave it highlighted while showing a related view.
However, if you store the current cell you have selected, you can call -deselectRowAtIndexPath:animated: on the tableview to deselect a row.
I have a UIPickerView that pops up from the bottom of the IPhone's screen when a UITextField begins editing. When a row is selected my UIPickerView is dismissed.
But the problem is that don't manage to select the first row which is shown under the selection indicator.
Right now I can select all except the first row. So the UIPickerView never dismisses and I can't choose that value.
The only workaround I found is to scroll a bit the picker in order to still select the first row, so when I "release the touch" the first row is selected. But it's not a good workaround I need the same behavior I have with the other rows.
Thanks for your help as usual.
Wallou
Bye
The way many apps do the trick is to add a button upon the picker to validate the selected item.
I have a list of things in a table view.
When a user tap a row, I increase score. I wish provide a way to clear the score for that row.
My first try is put the table in edit mode, show the delete button to that row and proceed. However, all the other rows get blocked and can't tap again the score or tap in the disclosure button.
So, obviously this is not the way. But then I don't see what to do. Any suggestion?
You could add a button to clear the row’s score as a subview of your table cell. I suppose you’d have to put it on the left side, though, since the disclosure button is on the right.