1

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.

TheTiger
  • 13,264
  • 3
  • 57
  • 82
Ali
  • 9,800
  • 19
  • 72
  • 152

2 Answers2

3

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

@interface OfferUIView : UIView <UIScrollViewDelegate>
Mick MacCallum
  • 129,200
  • 40
  • 280
  • 281
  • I did that the warning become disapear but the scrollView does not work. check my edit in the end of question. – Ali Oct 06 '12 at 10:13
  • @Ali What is the scroll view's `contentSize` set to, and is it a greater size than the scroll view's frame? – Mick MacCallum Oct 06 '12 at 10:14
  • As you see in my edit, I set the contentSize, It works when I set it from apple features but not programmatically, can you find out what is wrong? – Ali Oct 06 '12 at 10:17
  • what do you mean by this "apple features" @Ali? – Pratyusha Terli Oct 06 '12 at 10:29
  • It is possible to set content size programmatically.Your content size must be greater than your scrollview's frame size in order to see the scrolling – Pratyusha Terli Oct 06 '12 at 10:35
  • I think you need to see the code that I added to the end of the question. ContetnSize – Ali Oct 06 '12 at 10:40
3
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.

TheTiger
  • 13,264
  • 3
  • 57
  • 82
Manu
  • 4,730
  • 2
  • 20
  • 45