[英]iOS Scrollview detect Scrolling
我已經閱讀了有關此確切主題的所有先前文章,但仍然無法檢測到用戶何時在此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:
則滾動視圖的委托未設置為視圖控制器。
您可以在調試器中進行檢查。 應用啟動后,在調試器中暫停並運行以下命令:
po [[(id)UIApp keyWindow] recursiveDescription]
查看輸出以查找UIScrollView的地址。 會有一行顯示類似<UIScrollView: 0xc894d60 ...>
。 獲取地址(在我的示例中為0xc894d60
),然后在此調試器命令中使用該地址:
po [0xc894d60 delegate]
如果它打印類似<MyApp_ViewController: 0x6a7f6c0>
,則您的委托已正確設置。 如果它顯示“無法打印NIL對象的描述。”,則您尚未設置滾動視圖的委托。 如果打印出其他內容,則說明滾動視圖的委托設置不正確。
您是否將UIScrollView上的委托設置為ViewController?
對於可能像我一樣迷路的其他人,這是代碼中的解決方案:
- (void)viewDidLoad
{
[super viewDidLoad];
self.otherScrollView.delegate = self; // This is the KEY
檢查是否設置了委托,然后嘗試
嘗試實施`
- (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];
}
`
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.