首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UICollectionReusableView中的UIBUtton操作

UICollectionReusableView中的UIBUtton操作
EN

Stack Overflow用户
提问于 2018-08-27 20:20:29
回答 1查看 153关注 0票数 1

我在UICollectionReusableView中添加了UIButton。我可以添加按钮&它是动作,但按钮动作不起作用。我已经尝试添加TapGesture &启用UICollectionReusableView & button的用户交互,但没有效果。下面是我的代码

代码语言:javascript
复制
- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
        self.backgroundColor = [UIColor menigaLightBackgroundColor];
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:self.frame];
        imageView.userInteractionEnabled = YES;
        imageView.image = [UIImage imageNamed:@"Login_115"];
        imageView.contentMode = UIViewContentModeScaleAspectFill;
        imageView.tag = 10;
        [self addSubview:imageView];

        UIImage *titleImage  = [UIImage imageNamed:@"titleLogo"];
        UIImageView *imageViewTitle = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, titleImage.size.width, titleImage.size.height)];
        imageViewTitle.userInteractionEnabled = YES;
        imageViewTitle.center = self.center;
        imageViewTitle.contentMode = UIViewContentModeScaleAspectFit;
        imageViewTitle.image = titleImage;
        [self addSubview:imageViewTitle];

        float margin = 15.0;
        //Title Label  //10 is the tag for Arch image view
        titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(margin, CGRectGetMaxY([self viewWithTag:10].frame)+ 10 , CGRectGetWidth(self.frame)-margin*2, 60.0)];
        titleLabel.text = @"Your wallets have been linked successfully. Link more accounts now to fully understand your spending.";
        titleLabel.numberOfLines = 4;
        titleLabel.userInteractionEnabled = YES;
        titleLabel.textAlignment = NSTextAlignmentCenter;
        titleLabel.font = [UIFont getDINRegularFontOfSize:16];
        titleLabel.textColor = [UIColor menigaDarkTextColor];
        [self addSubview:titleLabel];

        //Buttons
        linkAccountButton = [[CustomButtonClass alloc] initWithFrame:CGRectMake(margin,  CGRectGetMaxY(titleLabel.frame)+ 10, CGRectGetWidth(self.frame)-margin*2, 44.0)];
        linkAccountButton.userInteractionEnabled = YES;
        linkAccountButton.layer.cornerRadius = 22.0;
        [linkAccountButton setTitle:@"Link An Account" forState:UIControlStateNormal];
        [linkAccountButton.titleLabel setFont:[UIFont getRobotFontOfSize:14]];
        [linkAccountButton setBackgroundColor:[UIColor menigaBrandColorRed]];
        [self addSubview:linkAccountButton];
        UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(linkButtonPressed)];
        tapGesture.numberOfTapsRequired = 1;
        [linkAccountButton addGestureRecognizer:tapGesture];

        [linkAccountButton buttonTouchUpInsideWithCompletion:^{
            MENIGAChooseOrganizationVC *vc = [[MENIGAChooseOrganizationVC alloc] init];
            vc.signupFlow = YES;
            [_parent.navigationController pushViewController:vc animated:YES];
        }];

        //set button hidden
        titleLabel.hidden = YES;
        linkAccountButton.hidden = YES;

    }
    return self;
}

下面是轻拍手势

代码语言:javascript
复制
//MARK:- Link button Action
-(void)linkButtonPressed
{
   OrganizationVC *vc = [[OrganizationVC alloc] init];
    vc.signupFlow = YES;
    [_parent.navigationController pushViewController:vc animated:YES];
}

我还浏览了下面的链接

Link

请帮帮我,我哪里做错了。

EN

回答 1

Stack Overflow用户

发布于 2018-08-27 23:15:24

在UIButtons上使用内部触控而不是手势识别器

代码语言:javascript
复制
[linkAccountButton addTarget:self action:@selector(linkButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

然后操作应该是:

代码语言:javascript
复制
-(void) linkButtonPressed:(UIButton*)sender
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52039253

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档