我已经阅读了之前关于这个主题的所有帖子,但我仍然无法检测到用户何时在此 iPad 应用上滚动...
我的.h:
#import <UIKit/UIKit.h>
@interface MyApp_ViewController : UIViewController <UIScrollViewDelegate>
{
}
@property (weak, nonatomic) IBOutlet UIButton *otherButton;
@property (weak, nonatomic) IBOutlet UIScrollView *otherScrollView;
@property (weak, nonatomic) IBOutlet UITextView *txtViewHTML;
-(void)k_RootViewPrint:(NSString *) data;
-(void)ActionEventForButton: (id) sender;
@end
我的.m:
-(void)scrollViewDidScroll:(UIScrollView *)scrollView
{
NSLog(@"...");
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSLog(@"2222");
}
- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event
{
NSLog(@"touches ended BS");
}
但是它们都不起作用?我确信这很简单,但我已经做了我能想到的一切,但仍然一无所获。任何正确方向的指导将不胜感激!
最佳答案
如果没有登录scrollViewDidScroll:
,则 ScrollView 的委托(delegate)未设置为 View Controller 。
您可以在调试器中检查这一点。应用程序启动后,在调试器中暂停并运行以下命令:
po [[(id)UIApp keyWindow] recursiveDescription]
查看输出以找到 UIScrollView 的地址。将会有一行内容类似于 <UIScrollView: 0xc894d60 ...>
。获取地址(在我的示例中为 0xc894d60
)并在此调试器命令中使用它:
po [0xc894d60 delegate]
如果它打印类似 <MyApp_ViewController: 0x6a7f6c0>
的内容,您的代表已正确设置。如果它打印“Can't print the description of a NIL object.”,则说明您尚未设置 ScrollView 的委托(delegate)。如果它打印出其他内容,则说明您错误地设置了 ScrollView 的委托(delegate)。
关于iphone - iOS Scrollview 检测滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8876451/