IOS Adding a button on TableView causes the buttons to have no click effect and no sliding issues

Source: Internet
Author: User

[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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.