2
こんにちはユーザーがアプリをスクロールしているときに関数をトリガーしようとしています。UIScrollViewDelegateが機能しない
- (void)viewDidLoad {
[super viewDidLoad];
self.scroll = [[UIScrollView alloc] init];
scroll.delegate = self;
[scroll setBackgroundColor:[UIColor whiteColor]];
NSInteger nbView = 3;
scroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.width, self.view.frame.size.height)];
for(int i = 0; i < nbView; i++) {
CGFloat xOrigin = i * self.view.frame.size.height;
UIView * vue = [[UIView alloc] initWithFrame:CGRectMake(0, xOrigin, self.view.frame.size.width, self.view.frame.size.height)];
vue.backgroundColor = [UIColor colorWithRed:0.5/i green:0.5 blue:0.5 alpha:1];
[scroll addSubview:vue];
[vue release];
}
scroll.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height * nbView);
[scroll setScrollEnabled:YES];
[self.view addSubview:scroll];
そして私を:ここで
は、私が書いたのviewDidLoadで、私は.Mで、@interface CircleViewController : UIViewController <UIScrollViewDelegate> {
UIScrollView *scroll;
}
@property (retain, nonatomic) UIScrollView * scroll;
@end
その後UIScrollViewDelegateを実装するクラスのMyViewControllerを定義し
私のコードであり、トリガーを定義します。
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"test");
}
アプリを実行するとスクロールできますが、scrollViewDidScrollは呼び出されません。
うわー、アンキット、私はそれを見なかったので、愚か:) – flocks
スクロールの2番目の割り当てが最初のものをオーバーライドし、デリゲートが失われました。 allocが新しいスクロールビューを作成するので、scroll = [[UIScrollView alloc] ...]の代わりに[scroll setFrame:]を2回目に使用することをお勧めします – Chaosphere2112