2012-01-16 80 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