2012-01-16 76 views
2

我读过所有关于这个话题确切以前的职位,但我当用户在这个iPad应用程序滚动仍然无法检测...的iOS滚动型检测滚动

我的.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"); 
} 

但他们都不工作?我确定这很简单,但我已经尽了我所能想到的一切,而且什么都没有。任何正确的方向指导将深受赞赏!

+0

你必须otherScrollView的委托设置为文件所有者 – Hiren 2012-01-16 06:34:30

回答

1

您是否将UIScrollView上的委托设置为您的ViewController?

+0

好,需要所有的被设置委托。谢谢。我知道这将是简单的 – Calderon 2012-01-16 15:02:43

0

检查您是否已经设置委托与否,然后尝试

尝试执行`

- (void) touchesEnded: (NSSet *) touches withEvent: (UIEvent *) event 
{ 
    // If not dragging, send event to next responder 
    if (!self.dragging) 
     [self.nextResponder touchesEnded: touches withEvent:event]; 
    else 
     [super touchesEnded: touches withEvent: event]; 
} 
` 
2

如果它不是在scrollViewDidScroll:登录,然后滚动视图的委托未设置为视图控制器。

您可以在调试器中进行检查。您的应用程序已经启动后,暂停在调试器中运行以下命令:

po [[(id)UIApp keyWindow] recursiveDescription] 

期待通过输出找到你的UIScrollView的地址。将会有一行说明如<UIScrollView: 0xc894d60 ...>。就拿地址(在我的例子0xc894d60),并在此调试器命令使用它:

po [0xc894d60 delegate] 

如果打印像<MyApp_ViewController: 0x6a7f6c0>,您的代理设置正确。如果打印出“无法打印NIL对象的描述”,则说明您尚未设置滚动视图的委托。如果它打印了其他内容,则您错误地设置了滚动视图的委托。

+0

以下是代码中的解决方案(对于其他可能像我一样丢失的人): - (void)viewDidLoad {super viewDidLoad]; self.otherScrollView.delegate = self; //这是关键 – Calderon 2012-01-16 15:03:32

1

对于其他人谁可能会丢失,好像我是,这里的代码解决方案:

- (void)viewDidLoad 
{ 
[super viewDidLoad]; 
self.otherScrollView.delegate = self; // This is the KEY