[Original]ios Add button on TableView causes buttons to have no click effect and cannot slide problem
2014-10-31 Read 202 comments 0
Reprint please indicate the source.
Today in debugging Code, add button on Tableviewcell, find button Quick Click, is not see Click Effect, find Data discovery,
iOS7 on the UITableViewCell sub-layer container is Uitableviewcellscrollview,
The IOS6 is uitableviewcellcontentview. The click Effect should be blocked by the scrollview touch delay.
After some groping, finally found a solution.
The first step: Set the delayscontenttouches of TableView to No,
Step Two: Add the following code in the initialization method of the custom cell
for (id obj in self.subviews) { if ([Nsstringfromclass ([obj class]) isequaltostring:@ " Uitableviewcellscrollview "]) { Uiscrollview *scroll = (Uiscrollview *) obj; Scroll.delayscontenttouches =no; break; } }
The above 2 steps can solve the problem of button no click Effect, but later found that if the sliding tableview, touch area just on the button, it is not sliding.
This time you have to
Step three: Customize a TableView inheritance UITableView, override this method
-(BOOL) Touchesshouldcancelincontentview: (UIView *) view{ return YES;
Originally the above method can be solved in iOS7, because the company to adapt to iOS8, when switching iOS8, found that there is no click Effect, and then find again.
Fourth Step: Add the following code in the custom TableView initialization method
For (ID view in self.subviews) { //looking for a uitableviewwrapperview if ([Nsstringfromclass] ([view class] ) {isequaltostring:@ "Uitableviewwrapperview"]) { if ([View Iskindofclass:[uiscrollview class]]) { / /Turn OFF delayscontenttouches in the hidden subview uiscrollview *scroll = (Uiscrollview *) view; Scroll.delayscontenttouches = NO; } break; } }
Or the fourth step is to add TableView to your Viewcontroller, plus the following code
if ([Uidevice currentdevice].systemversion.intvalue >= 8) {for (UIView *currentview in table.subviews) { if ( [CurrentView Iskindofclass:[uiscrollview class]]) { ((Uiscrollview *) currentview). delayscontenttouches = NO; Break;}}}
IOS Adding a button on TableView causes the buttons to have no click effect and no sliding issues