开发者

UIView not firing methods in the UIScrollView delegate

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.


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


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;


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜