【发布时间】:2017-12-05 08:45:04
【问题描述】:
我正在使用swipView制作页面滚动应用
根据它的SwipeViewDataSource协议,我做了一个方法
- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view
{
ContentViewController *contentVC = [[ContentViewController alloc]init];
view = contentVC.view;
return view;
}
提供刷屏内容
ContentViewController 很简单:
它只有这两个自定义方法:
- (void)viewDidLoad {
[super viewDidLoad];
UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 100, 200)];
[btn setTitle:@"click me" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor redColor]];
[btn addTarget:self action:@selector(onClick:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void) onClick:(id) sender {
NSLog(@"click detected in contentView controller");
}
只在viewDidLoad中添加了一个按钮和点击监听方法
运行应用程序时,显示按钮,但单击时不要触发OnClick: 方法。
琢磨了一下,发现如果我把这个方法放了
-(void) onClick:(id)sender {
NSLog(@"on click detected main view controller");
}
到实现SwipeViewDataSource 的视图,即在初始化ContentViewController 的“父级”中,将打印该行调试信息。
对我来说,这很奇怪。我的意思是为什么会这样?
【问题讨论】:
-
创建 ContentViewController 的强属性并尝试
标签: ios objective-c viewcontroller