@interface SecondViewController : UIViewController @property(nonatomic,copy)NSString *contents; @end
- (void)buttonAction:(UIButton *)button
{
NSLog(@"进入第二页");
SecondViewController *secondVC = [SecondViewController alloc] init];
secondVC.contents = self.label.text;
[self.navigationController pushViewController:secondVC animated:YES];
}
@implemention SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
self.navigationItem.title = self.contents;
}
#pragma mark 这里是B的.h #import<UIKit/UIKit.h> @protocol CsutomTabBarDelegate<NSObject> // 把btn的tag传出去的方法 - (void)selectedIndexWithTag:(NSInteger)tag; @end @interface CustomTabBarView : UIView //声明一个代理属性delegate @property (nonatomic,weak)id<CsutomTabBarDelegate>delegate; @end
#pragma mark 这里是B的.m
// 判断在制定的代理类中是否实现了该协议方法
// 确保执行时无此方法时不崩溃
if([self.delegate respondsToSelector:@selector(selectedIndexWithTag:)])
{
// 执行代理方法
[self.delegate selectedIndexWithTag:(sender.tag - 1000)];
}
else
{
NSLog(@"协议中的方法没有实现");
}
#pragma mark A的.m中 // 指定代理,B就是customView customView .delegate = self;
#pragma mark A的.m的延展里,A就是RootTabBarController // 协议导入 @interface RootTabBarController () <CustomTabBarDelegate> @end
#pragma mark A的.m
// 实现代理方法,这里就可以使用从B传来的值了
- (void)selectedIndexWithTag:(NSIngeter)tag
{
self.selectedIndex = tag;
}
#pragma mark B的.h #import <UIKit/UIKit.h> // block传值 // 重命名一个有参无返回值的block类型 typedef void(^passValue)(NSInteger tag); @interface CustomTabBarView : UIView //用这个block类型定义一个属性 @property (nonatomic,copy)passValue passValueTag; @end
#pragma mark B的.m的返回方法中 //调用block方法 self.passValueTag(sender.tag - 1000);
// 设置block内容
customView.passValueTag = ^(NSInteger tag)
{
self.selectedIndex = tag;
};
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有