Skip to content
This repository has been archived by the owner on Nov 29, 2022. It is now read-only.

Why a button on the customViewForEmptyDataSet can not respond click event? #168

Closed
ApesTalk opened this issue Dec 2, 2015 · 12 comments
Closed

Comments

@ApesTalk
Copy link

ApesTalk commented Dec 2, 2015

In my project,i need a custom view for the customViewForEmptyDataSet. I put a button on my custom view but it can not respond a click event.My code is here:

-(UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
{
UIView *holderView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kFrameWidth, kFrameHeight)];

UIImageView *noDataHolder = [[UIImageView alloc]init];
noDataHolder.userInteractionEnabled = YES;
noDataHolder.image = [UIImage imageNamed:@"nodataholder"];
[holderView addSubview:noDataHolder];
[noDataHolder mas_makeConstraints:^(MASConstraintMaker *make) {
    make.width.equalTo(@250).priorityHigh();
    make.height.equalTo(@320).priorityHigh();
    make.center.equalTo(holderView);
}];

UIButton *reloadBtn = [UIButton buttonWithType:UIButtonTypeCustom];
reloadBtn.backgroundColor = kThemeColor;
reloadBtn.layer.cornerRadius = 5;
reloadBtn.titleLabel.font = [UIFont systemFontOfSize:16];
[reloadBtn setTitle:@"重试" forState:UIControlStateNormal];
[reloadBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[reloadBtn setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];
[reloadBtn addTarget:self action:@selector(yl_reloadDataAction) forControlEvents:UIControlEventTouchUpInside];
[holderView addSubview:reloadBtn];
[reloadBtn mas_makeConstraints:^(MASConstraintMaker *make) {
    make.width.equalTo(@80).priorityHigh();
    make.height.equalTo(@35).priorityHigh();
    make.bottom.equalTo(noDataHolder).offset(-55);
    make.centerX.equalTo(noDataHolder);
}];

return holderView;

}

How can i let the reloadBtn respond a UIControlEventTouchUpInside event?

@migrant
Copy link

migrant commented Dec 3, 2015

The author has fixed this issue in #119 and commit in f5e7aee.
But the newest version has been neither released nor pushed to Cocoapods.

@ApesTalk
Copy link
Author

ApesTalk commented Dec 3, 2015

Thank you!

@dzenbot
Copy link
Owner

dzenbot commented Dec 17, 2015

Is it just coincidence that you guy's avatars kinda bond? 😂

@dzenbot dzenbot closed this as completed Dec 17, 2015
@dzenbot
Copy link
Owner

dzenbot commented Dec 17, 2015

BW, will release a new pod soon including this fix ✌

@migrant
Copy link

migrant commented Dec 18, 2015

It is absolutely a coincidence.
And looking forward to the new release.

@dean-gr
Copy link

dean-gr commented Jan 25, 2016

Pulling the pod directly from Github by using the git option in my Podfile. It still doesn't work with the fix for #119. UIButton on my custom view doesn't respond.

I do it like this by the way:

- (UIView *)customViewForEmptyDataSet:(UIScrollView *)scrollView
{
    EmptyHistoryViewController *ehVC = [[EmptyHistoryViewController alloc] init];
    return ehVC.view;
}

EmptyHistoryViewController is where I initialize the button and have its IBAction. The button is animating when tapped in the view but the action is not triggered.

Also tried using - (void)emptyDataSetDidTapButton:(UIScrollView *)scrollView but no luck.

Hope you could help me out. Great job on the pod by the way. Thanks.

@colinhumber
Copy link
Contributor

Running into the same issue as @dean-gr.

@Guoxweii
Copy link

+1

@ZhongYanga
Copy link

Does it has been solved? I am still have the same issue

@colinhumber
Copy link
Contributor

It's fixed in #347, but I don't think this is being overly maintained anymore as the last commit was 5 months ago.

@romeugodoi
Copy link

+1

@jeanmartin
Copy link

wait, is this still not merged and released or am I doing something else wrong trying to get a button in my custom view tappable?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants