iOS Development essay 31:uibutton Unable to respond to click events

Source: Internet
Author: User

Problem description

Because the project requires, you need to add a fixed filter header on UITableView, always fixed, and cannot scroll with UITableView. So separate the header from the UITableView, add it to the controller's UIView, add it to the parent view of the UITableView, and the UITableView sibling. Then add three UIButton to the header, and the effect is expected, but the problem appears. Filtering the UIButton on the header does not respond to the Click event, initially thinking that the cause is that the hand mistakenly uibutton the parent view or the UIButton property userinteractionenabled is set to No, Trying to uibutton the parent view and the UIButton userinteractionenabled all set yes will still not solve the problem.

Problem analysis

There are three reasons why UIButton cannot respond to click events:

1. UIButton userinteractionenabled Default Yes, if the settings No,uibutton there will be no response to the Click event, and if the UIButton parent view's Userinteractionenabled property is no, UIButton will also be affected and will not respond.

It's not a problem to set yes from UIButton's parent view and UIButton's userinteractionenabled, which is still unresolved.

2. The other is the frame problem of the button itself, or if there is no layer of view that covers the button causing it to be unresponsive, simply the button itself and the button's father (parent view) problem.

3. Another reason UIButton cannot respond to a click event is to have a relationship with the parent view of UIButton. If the parent view frame is Cgrectzero, or UIButton is out of the parent view, UIButton will still be displayed, but the weird thing is that UIButton won't respond to the Click event, so adjust the parent view's frame or UIButton position.

The first kind: tried, ruled out.

The second type: Because of the use of Mbprogresshud, so the second is possible. But after debugging, found that Mbprogresshud is hidden, do not block the Click event, while assuming that Mbprogresshud is not hidden, should be the same level of UITableView can not click, but UITableView can respond to click events, so the second is also excluded.

The Third kind: But first set UIButton's parent view background color to be red, at the same time first UIButton all to remove, debugging discovers UIView did not show out. Print UIView frame with a value of {{0, 0}, {414, 44}}. It turns out that the problem appears here. Why can't I show it?

I set up the frame and set the constraint with masonry. The constraint is set, frame is invalid, and UIView cannot be displayed because the constraint settings are unreasonable.

    [Self.filerview mas_makeconstraints:^ (Masconstraintmaker * make) {        make.left.equalTo (self.view.mas_left);        Make.right.equalTo (self.view.mas_right);        Make.top.equalTo (self.view.mas_top);    }];

Problem solving

UIView frame is removed, and a height constraint is set.

    [Self.filerview mas_makeconstraints:^ (Masconstraintmaker * make) {        Make.left.equalTo (strongSelf.view.mas_ left);        Make.right.equalTo (strongSelf.view.mas_right);        Make.top.equalTo (strongSelf.view.mas_top);        Make.height.equalTo (@);    }];    

The effect is as follows:

Then add Uibutton,uibutton to respond to click events

iOS Development essay 31:uibutton Unable to respond to click events

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.