1
votes

I have a UIView in my .xib file. (note that not a UIControlView)

@interface OfferUIView : UIView

So the custom class for my UIView is OfferUIView

I want to add a scrollView to it. when I add it using xcode features, I just connect the delegate of scrollview to OfferUIView. How can I do it programmatically in OfferUIView.m?

This is what I dit :

self.scrollView = [[UIScrollView alloc] initWithFrame: frame];
self.scrollView.delegate = self; 

But I get a warning on the delegate = self like this:

Assigning to id<UIScrollViewDelegate> from incompatible type OfferUIView

Do you know how can I fix it?

Edit:

when I use

@interface OfferUIView : UIView <UIScrollViewDelegate>

self.pageViews = [[NSMutableArray alloc] init];
    for (NSInteger i = 0; i < pageCount; ++i) {
        [self.pageViews addObject:[NSNull null]];
    }

    CGRect frame = self.view.bounds;
    self.scrollView = [[UIScrollView alloc] initWithFrame: frame];
    CGSize pagesScrollViewSize = self.view.frame.size;
    self.scrollView.contentSize = CGSizeMake(pagesScrollViewSize.width * self.pageImages.count, pagesScrollViewSize.height);
    self.scrollView.delegate = self;

It should be couple of images in UIScrollView, but scroll does not work.

2
in yourView Controller just put this <UIScrollViewDelegate> - Manu
Thanks, please check my edit at the end of the question. - Ali
You are placing scrollview through xib rite ? If it is so then remove this self.scrollView = [[UIScrollView alloc] initWithFrame: frame]; - Manu
No, I created it programmatically. check the code. - Ali

2 Answers

3
votes

You have to specify that your class should conform to UIScrollViewDelegate.

@interface OfferUIView : UIView <UIScrollViewDelegate>
3
votes
scrollView =[[UIScrollView alloc]initWithFrame:CGRectMake(10, 402, 750, 600)];
scrollView.delegate = self;
scrollView.scrollEnabled = YES; 
[self.view addSubview:scrollView];
[scrollView setContentSize:CGSizeMake(654, ([reports_list count]+1)*110)];

It Worked for me... Just Try it.. And Ignore the frames.