xcode 以编程方式为 .xib 中的 UIScrollView 设置委托
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12758754/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Set Delegate Programmatically for a UIScrollView in .xib
提问by Ali
I have a UIView in my .xib file. (note that not a UIControlView)
我的 .xib 文件中有一个 UIView。(注意不是 UIControlView)
@interface OfferUIView : UIView
So the custom class for my UIView is OfferUIView
所以我的 UIView 的自定义类是 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?
我想给它添加一个滚动视图。当我使用 xcode 功能添加它时,我只是将滚动视图的委托连接到 OfferUIView。如何在 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:
但我收到这样的警告delegate = self
:
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.
它应该是 UIScrollView 中的几个图像,但滚动不起作用。
回答by Mick MacCallum
You have to specify that your class should conform to UIScrollViewDelegate.
您必须指定您的类应符合UIScrollViewDelegate。
@interface OfferUIView : UIView <UIScrollViewDelegate>
回答by Manohar Perepa
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.
它对我有用......试试吧......并忽略框架。