UIView not firing methods in the UIScrollView dele

2019-05-31 17:51发布

I wonder if someone could please shed some light as to why any of the methods in UIScrollView delegate are not being fired.

To set the scene. I have a UIViewController which is pushed onto a stack. On this view I have 5 custom tabs that I have made. On a tap of each tap I have a function with loads of 5 views (one per tab) from UIViewController/xib combo.

ExercisePhotoView *exercisePhotoView = [[ExercisePhotoView alloc] initWithNibName:@"ExercisePhotoView" bundle:nil];
exercisePhotoView.exercise = self.exercise;
[self.photoView addSubview:exercisePhotoView.view];
[exercisePhotoView release];

On one of these views that gets loaded I have a a scroll view with some images in (the above code block is the said view). The self.exercise is an NSManagedObject. The images are loaded fine into the scrollview controller and the paging works. What however does not work is any of the ScrollView's delegate methods such as

- (void)scrollViewDidEndScrollingAnimation:(UIScrollView *)theScrollView

I have included a reference to the delegate in my header file like so.

@interface ExercisePhotoView : UIViewController <UIScrollViewDelegate> {
    IBOutlet UIScrollView   *scrollView;
    IBOutlet UIPageControl  *pageControl;

    Exercise                *exercise;
    NSMutableArray          *exerciseImageList; 
}

Is there something that I am missing or doing wrong. I cannot get any of the delegate methods to fire on the ExercisePhotoView class.

Thank you in advance.

4条回答
欢心
2楼-- · 2019-05-31 18:31

You must tell the scroll who it's delegate is, so that I knows who to send the delegate Notifications to.

查看更多
劫难
3楼-- · 2019-05-31 18:39

Whilst you have stated that the ExercisePhotoView implements the UIScrollViewDelegate protocol, you have not informed it of any instances of a UIScrollView that it is the delegate for.

Therefore, in viewDidLoad of ExercisePhotoView (or other appropriate method), you need to declare that the ExercisePhotoView is the delegate for the specific scrollView instance:

scrollView.delegate = self;
查看更多
姐就是有狂的资本
4楼-- · 2019-05-31 18:46

Remember to add @property (nonatomic, retain) UIScrollView *scrollView; in your header and @synthesize scrollView; in your .m

查看更多
兄弟一词,经得起流年.
5楼-- · 2019-05-31 18:54

You have to set self.scrollView.delegate to the object that should act as a delegate to the scrollView.

查看更多
登录 后发表回答