uiview类里面进行触发按钮事件来让viewcontroller进行跳转的方法

1:

代理,block 都可

说实话代理不熟,一般自己定义一个UIView 中含有button ,并且button的 是push事件我都用block,回调到调用该view的ViewContronller中用
[self.navigationController pushViewController:secondVC animated:YES]  实现push事件。

或者还可以这样
假定你的项目中有文件 UIViewContronller1(继承UIViewContronller), UIViewContronller2(继承于UIViewContronller),UIViewWithButon(继承于UIView)
UIViewWithButon中有一button
在UIViewContronller1中调用UIViewWithButon
目的是:点UIViewWithButon上的Button就会从UIViewContronller1 push到 UIViewContronller2
实现是:
在UIViewWithButon.h文件 @property (nonatomic,strong) UIViewController *owner;
在UIViewWithButon.m文件中button 的方法中 [self.owner.navigationController  pushViewController:[UIViewContronller2 new] animated:YES];

在UIViewContronller1,.m中调用UIViewWithButon
UIViewWithButon *buttonView = [[UIViewWithButon alloc]initwith...];
buttonView.owner = self;
2:

用代理 首先在view 中 声明协议
.h文件
@protocol AccountBindingDelegate <NSObject>
- (void)jumpWebVC:(UIButton*)sender;
@end
@interface CustomRegisterView : UIView
@property (nonatomic, weak) id<AccountBindingDelegate> delegate;
@end

.m文件
[agreementBtn addTarget:self action:@selector(agreementBtnClick:) forControlEvents:UIControlEventTouchUpInside];//button的点击方法

- (void)agreementBtnClick:(UIButton*)sender
{
    if (self.delegate && [self.delegate respondsToSelector:@selector(jumpWebVC:)]) {
        [self.delegate jumpWebVC:sender];
    }
}

在controller中
@interface uiviewContrller ()<AccountBindingDelegate> //遵守协议

@end

- (void)viewDidLoad {
    _registerView.delegate = self;//设置代理
}

//实现方法
- (void)jumpWebVC:(UIButton*)sender
{
    PSMFWebVC *webVC = [PSMFWebVC new];
    UIBarButtonItem *backItem = [UIBarButtonItem new];
    backItem.title = @"返回";
    self.navigationItem.backBarButtonItem = backItem;
    [self.navigationController pushViewController:webVC animated:YES];
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值