I am adding a my header view to
self.tableView.tableHeaderView=headerView;
This tableView has 10 cells.
I want to disable the cell Selection but, headerView touch events must be enabled.
To achieve this I added the following code:
self.tableView.userInteractionDisabled=YES;
self.headerView.userInteractionDisabled=NO;
self.headerView.exclusiveTouch=YES;
Where I am wrong?
Basic idea of implementation is , If headerView is enabled then cell selection is disabled and vice-versa.
I'm not sure that I completely understand what you are asking, but if you want to avoid seeing any cell highlighting set the UITableViewCell selectionStyle to UITableViewCellSelectionStyleNone. That's what I do, and then don't implement the UITableViewDelegate method tableView:didSelectRowAtIndexPath:.
I've never tried it, but I'm pretty sure you can also disallow the selection of any rows by setting the UITableView property allowsSelection to NO.
The userInteractionDisabled property of the table view should be set to NO. Otherwise your headerView, which is a subview of tableView, will not get touch events. Setting a superview's userInteractionDisabled property to no disables touch events for all of its subviews.
Related
I have a custom cell in table view, which allows multiple selection. Can i limit the cell selection area of a custom cell. Can i enable selection area to only the left side of the cell not the entire cell.
Please share your thoughts.
In your UITableViewCell subclass override pointInside:withEvent: method and return YES only for the points inside the area you want.
Yes, the way you want can be implemented, You make a button on left side of your cell. So Whenever you click on button your selected are will be enabled.
You do not need to implement any logic in UITableView DidSelectRowForIndexPath.
Need to manage in your button.
You can add a UIButton on the left side of your cell, by this way you can easily handle the selection of UIButton by using its tag value.
In the custom tableView Cell. The are which you want to be non clickable add a button to that area and if a tap is registered in the button the didselectitem at indexPath would not be called I have done a similar implementation myself.
My TableView Implementation
I have a tableview with a number of custom cells. The problem I am having is that the cell with the pickerview is 'bleeding' behind the neighboring cell.
Once I push another view controller and pop back, the neighboring cell is properly opaque until I manipulate the picker, at which point the issue materializes again.
The cell is, in fact, opaque. I have set it as such in both the storyboard and code. I have also tried setNeedsLayout and layoutIfNeeded in cellForRowAtIndexPath.
Set clipsToBounds property to true to each cell in the method cellForRowAtIndexPath.
You can set this property in the Storyboard if you are using prototypes cells.
You need to provide more information.
But if I understand correctly, you should hide the cell that contains the picker and only show it when the user will input.
Here is a tutorial on how to hide the cell, like the calendar iOS app does.
http://www.appcoda.com/expandable-table-view/
I use custom cells of subclassing UITableViewCell in a table view. And There must be space between cells. I succesfully add the space with adding a subview that I called SpaceView into the content view. But When I touched the spaceView, it is perceived as I touched the cell. And didSelectRow method called. I tried to set spaceView's UserInteractionEnabled==NO. But It doesn't work.
So my question is; Is this the right way I used to add space between cells ? Should I try to add cells for making the space ? or If its the right way, How can I prevent calling "didSelectRowAtIndexPath" method when I touched spaceView ?
like Inder said below, u can use an UIButton to solve the issue.
1) in your custom cell: at the bottom of your custom cell add a blank UIButton with the height u actually need between cells, and customize its background color according to your needs.
2) in cellforrowatindexpath: disable button of each cell. (or you can also do that in Interface Builder of previous step)
result: u have a clear disabled button that will appear as required space between cells.
Make your spaceView as UIButton (I guess it's UIView right now)
When you add UIButton that touch will be consumed by the button thus touch won't be passed to it's parent.
OR
I'm not sure if it will work or not, you can add tap gesture to your spaceView
I have a static UITableView with various cells in it. I need to hide/show some of those cells, so I've implemented heightForRowAtIndexPath and return 0 when appropriate in order to hide the right cells. This works great for sighted users, but for those who use VoiceOver those elements are still highlighted and accessible when they should not be. How can I ensure those UITableViewCells are no longer accessible when I change their height to 0?
I've tried setting the cell to not be an accessible element as well as setting the elements to be hidden but this has no effect on it. The cell has not been subclassed - it's just a UITableViewCell. I have not set anything in regards to accessibility on the cell nor the cell's contents (textLabel, detailTextLabel).
Doesn't do the trick:
self.cellToHide.isAccessibilityElement = NO;
self.cellToHide.accessibilityElementsHidden = YES;
Update Cell VoiceOver Elements By Reloading Cell(s)
After reading about a UITableView taking control over Accessibility elements and observing apps that have similar features, I figured that a TableView must update its Accessibility information upon loading or reloading a cell. I tried forcing the cell to reload after changing its Accessibility properties and that solved the problem. VoiceOver information was updated.
The following is an example of code that runs when the cell in question is tapped. Alternatively, it could run when some other event requires that VoiceOver elements are updated.
// Make changes to accessibility properties such as
cell.isAccessibilityElement = false
cell.accessibilityElementsHidden = true
// reloadRows() allows VoiceOver to update its element list for the related cell(s)
// "indexPath" is for the desired row
// reloadRows() expects an array of IndexPaths so an array of one is created inline
tableView.reloadRows(at: [indexPath], with: .automatic)
// Calling UIAccessibilityPostNotification() is not necessary to realize the VoiceOver changes in the TableViewCell
Background
I wrestled with this problem for a while before finding a solution. In my case the TableView cells are created in code. There are no storyboards or nibs involved. However, this solution should work regardless of how the TableView was constructed.
I have custom, subclassed TableView cells with view hierarchies built in code and added as a subview of the UITableViewCell's contentView. I assumed I could modify the isAccessibilityElement and/or accessibilityElementsHidden properties of various subviews and call UIAccessibilityPostNotification() to realize the VoiceOver changes as I have done outside of TableView's. These changes were not recognized by VoiceOver, only the accessibility state the cell was in when it was loaded was recognized.
For the cell I wrestled with, the height dynamically changes to accommodate a DatePicker that is shown and hidden on cell tap. I only want the DatePicker visible to VoiceOver when it is visible on the screen. I try to avoid reloading the TableView, Sections or Rows to make dynamic changes if at all possible. If I have to reload, I try to make it as isolated as possible (reload one cell or one section not the whole TableView). In this case I did not need to reload anything to make the cell expand to reveal the DatePicker so it did not occur to me try reloading the cell for Accessibility updates.
Related Information: UIAccessibility API Reference on Apple's web site
Try adding below code after you set accessibilityElementHidden.
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, yourTableView);
I have a custom UITableViewCell with a custom selectedBackgroundView. Is there a delegate method when the selectedBackgroundView shows? For example, if I press one cell and keep it pressed, the cell is highlighted and the selectedBackgroundView is showing. I want to change one of the cell's subviews when this happens.
I have tried using the gesture recognizer's delegate method -(BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer, but this gets called too late. I want a to know the second it starts that selection animation. If this can't be done, is there a way to make the selectedBackgroundView be on top of all the cell's subviews?
Figured it out. You have to override -(void)setHighlighted:(BOOL)highlighted animated:(BOOL)animated and perform the changes there. I also tried overriding the touchesBegan event, but doing this completely removes the cell's selection (doesn't get selected anymore).