UITableViewCell didTransitionToState Not Redrawing nonvisible cells - ios

I currently have a UITableView that contains editable UITableViewCells. When a cell goes into edit mode, i use the willTransitionToState and didTransitionToState to show/hide a UITextField when the cell goes into edit mode. The problem, is if I have invisible cells, the willTransitionToState/didTransitionToState does not get called when they become visible... so the cells still look like they are in edit mode. Does anyone have a suggestion to fix this?

Hiding/unhiding subviews of your UITableViewCell do not constitute a change of state, that's why those methods don't get called.
Depending on your implementation, you could invoke those methods yourself when hiding/unhiding. But in general, you should implement the hiding/unhiding logic in those methods, not outside of them, e.g. a change of state leads to the change of the subviews, not vice versa.
For more concrete answers you should provide samples of your code and get more concrete on what you are trying to achieve.
Peter

Related

Is it possible to have a UITableView with one row always in edit mode, showing its insertion or deletion control? If so, how?

I have a UITableView with some data, and I'm hoping to put in the top row or section a cell (call it, "Add Record" or something), which is always in edit state, so that it always displays the system insertion control. Is this possible? If so, how?
I've searched all around for this. Apple's documentation lists a setEditing(_:animated:) method on UITableViewCell. I used both that and setting isEditing to true on the cell on load, and it appears to be in isEditing state because the table wouldn't let it be selected until I turned on 'single selection in edit state'. But no insertion or deletion controls show up, and the delegate's tableView(_:editingStyleForRowAt:) is never called.
The cell looks fine if I call setEditing(_:animated:) on the table view itself, but that sets every cel to editing, deletion and all! That's not what I want.
I suppose I can just use a normal cell, and use an image of an insertion control, but I'd rather use Apple's system one if possible (since they might change). Aside: I could always load up an editing table on load and cache a snapshot of an editing control, but that's waaaay more work than its worth!
Is what I'm going for even possible? Do you understand what I'm going for? Any advice you could provide would be very helpful.
You can try the following approach:
Keep using setEditing on the UITableView itself.
To show the editing controls only for a specific cell, implement the
canEditRowAtIndexPath method of the
UITableViewDataSource delegate and return true only for the cell that you wish to allow editing for.
At this point your specific cell will show the editing controls, but the cells are not selectable; you'll need to set allowsSelectionDuringEditing on your table-view
to allow the cells to get selected. Next, you will probably want to
prevent the editing cell from being highlighted by implementing
shouldHighlightRowAtIndexPath delegate method and return true for
all cells except for the cell that you want to keep in editing mode.
Other possible solutions:
Create your own UITableViewCell and implement the editing UI yourself (which will always be visible), then use this cell where you need it.
Use another UITableView with a single cell which will always be in editing mode and place it above your other table so it would appear to be the same table. It's a possible solution but most likely an overkill.

How can I Create a Tableview Under Custom Tableview cell

I am just thinking. Suppose, i have a tableview which have custom cell. It's simple. But My idea is that, when i click a tableview cell then another tableview is appear under that tableview cell, and again i click that cell then that sub tableview disappear. Similarly when i click second cell than work same. Is it possible? Please Provide me any idea or reference.
This is entirely possible, you're talking about Expandable cells.
My example here
The general idea is that your custom cell has a tableview at the bottom of the cell, and what you do is just change the cell height to display said tableview, on tap.
It's not easy, I'm not gonna lie it took us a while to do it, but we managed, and I'm telling you, it's very possible.
You can find a lot of help using the Expandable Cell keywords.
Note that you're gonna find yourself handling a lot :
What to do when the expanding cells is shown off screen?
What to do when you're expanding the first/last cells ?
What to do when expanding another cell ?
What to do when scrolling inside that cell (a scrollview inside a scrollview !)
There are many cases where it'll work, but won't work fine, and there is gonna be a lot of fine tuning. Specially in our case where we have rounded corners, but only when the cell is expanded, and not in cases where it's the last or first cell (next to section header).
They look cool and make you feel proud, but don't say to your PM it'll be done in a week, because it's a pain to build.
If you want to show additional cell information, you can add more cells after the cell indexpath you have clicked.
Create a custom table view cell classCustomTableViewCell by subclassingUITableViewCell class. And system will generate CustomTableViewCell.h, CustomTableViewCell.m, CustomTableViewCell.xib files for you.
Add protocols UITableViewDataSource and UITableViewDelegate in your CustomTableViewCell.h and implement the required methods in CustomTableViewCell.m files
Add a method for setting datasource and use the datasource for updating the table.
NOTE:
Handle table-dequeue mechanism properly, otherwise you will end up
with weird issues that may take time to investigate and resolve.
If you use this custom cell for all the cells in your parent table then the gestures will only listened by the child table. So plan for that too.
Please visit my blog for the sample code. https://myioslearnings.blogspot.in/2017/03/nested-table-view-in-ios-objective-c.html

VoiceOver not reading UITextField subviews

I've got a few custom UITableViewCells that I'm making accessible. I'm trying to get VoiceOver to read all the subviews when the cell is tapped. From my understanding, this is something you get for free when using or sublcassing UITableViewCell (Correct me if I'm wrong on that.)
The issue is in a few of my cells. In most of my cells, everything reads correctly. However, when I tap on a cell that contains a UITextField (or subclass of UITextField) it does not read the UITextField. It will read all the other elements (except the UIButton on one cell as well,) but will skip the text fields.
Does anyone know any reasons it would not read the UITextFields? And the one UIButton? Is there something special that needs to be done for those to be read? Or something special to be done to a UITableViewCell subclass that I haven't done?
Sorry for posting no code, I'm not really sure what code would be relevant to post since I don't see anything related to accessibility at all in the code. In the storyboard, it is selected as accessible for all elements I want read, however the UITextFields seem to ignore this setting.
What you want to do is create a custom cell class, and override the accessibilityLabel property of that class. Collecting all subviews accessibility labels. I'm on a windows machine now, so pardon if this doesn't quite compile, but you should get the idea.
#implementation MyCustomCellViewClass
-(NSString*)accessibilityLabel {
NSMutableString* result = [NSMutableString new];
for (subview in [view accessibilityElementViews]) {
[result append:subview.accessibilityLabel];
}
return result;
}
By including this as a property override, rather than setting accessibility labels at all potential points that it changes, you remove the concern of future devs overriding this behavior. You also gain automatic handling of dynamic elements within these cells, as the accessibility label will simply stay in sync with the accessibility information of the subviews. You can then include this class as a parent class of any future subclasses to trivially maintain this behavior. If any of your devs are dumb enough to remove this sub class from the inheritance tree you have bigger problems to deal with!
Make sure with this approach that your cell has the correct role. Whatever the active element of the cell is (be it a tab, link, button, etc) should be the role of your super view. The other elements are just informative.
Let's say your table cell has 4 elements a label, a button, a text field, a image view. All these elements are in the contentView of your tablecell.
To make sure the voice over reads all the 4 elements in your table cell, you need to tell the voice over that your contentview contains 4 elements.You can do this by adding all the elements in your contentView to the contentView's accessibilityElements Array.
contentView.accessibilityElements=#[label,button,textField,imageView];
Then the voice over will not skip any of these 4 elements.

iOS Maintaing selected button in Tableview when scrolling

I have a UItableView with custom cell. There are multiple sections, and in those sections multiple rows. In each cell, I have a segment button for "Yes" and "No" selections. I would like to maintain the selections for the segment button when I scroll up and down the table. Can anyone please help. I have looked and did not find anything that helped me. Thank you!
You have multiple ways to do this.
The first one, which I think is the best one, is to use the selected state for the uitableviewcell.
With this method, the table view it self will set the cell's state and according to that state will call didselect or diddeselect on its delegate. Since all is managed by the table view, you don't need additional logic on your cellForRow method, and don't even need to worry about cell reuse.
Another way is to always set the state of your cell's buttons in cellForRow. For this, you need to keep a reference to all the selected rows, and to be able to manage reused cells, you need to make sure its state is always set on cellForRow.
I prefer the first one, but whatever suits you better.

Resize TableCell on select/deselect

I'm new to iOS and MonoTouch, and I have a pretty basic need - I have two vastly different views to display in the same table cell depending on whether it is selected or not. When you load the app I'll present a list of products in a custom UITableView, with all the rows deselected and each row basically just showing the product names in a label. As soon as a user taps one of the rows and selects it, I show a very different view with more of a shopping cart layout. Since the two views are so different they have vastly different sizes. What i need is for the cell itself (or row?) to grow and shrink according to the natural height of whichever view is currently being displayed.
I'm using descendants of UITableViewController, UITableViewSource, and UITableViewCell for the solution. What I do is add both versions to the cell's ContentView, then set the Hidden property as needed when the cell/row is selected/deselected to show the right layout. That works well. I'm in demo mode right now, so I'm not overly worried about efficiency or responsiveness, that will have to come later.
I know that GetHeightForRow is responsible for sizing the rows but it only gets called once, when the cell is first shown. It seems to me that I need to alert the TableView to re-poll the source for a new size as the views are changing, but I can't figure out how to do it.
I tried (rather hopefully) to cause GetHeightForRow to be invoked again manually using Cell.SetNeedsLayout and Cell.SetNeedsDisplay, hoping that would cause the table to re-query the source for new dimensions, but no joy.
I tinkered with the direct approach, trying to size the contentview itself but it didn't seem as if it was leading anywhere. I feel as if the table needs to be told to query for a new row size, but I'm open to any suggestions.
Surely I'm not the first to attempt this? What am I missing?
Try forcing GetHeightForRow to be called again by calling ReloadRows instead.
You may or may not have to specify begin/end updates (this might just be for animation, though?)
tableView.BeginUpdates();
tableView.EndUpdates();

Resources