【发布时间】:2011-04-15 08:06:35
【问题描述】:
早上好,
我创建了 UIScrollView 的子类,现在我想知道用户何时在我的子类中滚动。为此,我将其实现如下:
ImageScroller.h
@interface UIImageScroller : UIScrollView <UIScrollViewDelegate> {
ImageScroller.m(在@implementation 中)
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
NSLog(@"did scroll");
}
问题是,scrollViewDidScroll 方法似乎没有被触发。 有没有可能让它工作?
我也尝试将委托设置为自己,但它不起作用。
- (id)initWithCoder:(NSCoder *)aDecoder {
if ((self = [super initWithCoder:aDecoder])) {
self.directionalLockEnabled = YES;
[self setDelegate:self];
}
return self;
}
我在我的 XIB 文件中添加了一个 ScrollView,并将 Class 设置为我的 ImageScroller。我还设置了 Fileowner 并在 ViewController 的 .h 文件中使用 UIScrollViewDelegate 以及在 .m 文件中实现方法 scrollViewDidScroll。
当我在 XIB 的 .m 文件的代码中设置 ImageScroller 的委托时,例如 [imageScroller setDelegate:imageScroller] scrollViewDidScroll 在我的 ImageScroller-Subclass 中被触发,但我的 ViewController 中的那个没有被触发,但我需要两者。
有什么解决办法吗?
提前感谢您的回答。
【问题讨论】:
标签: iphone uiscrollview subclass