2012-02-29 87 views
0

我想觸發scrollsToTop函數,當用戶點擊導航欄標題時,通過編程方式點擊狀態欄時觸發。如何以編程方式點擊狀態欄後觸發「scrollsToTop」?

這是我目前的方法。

[tableView_ setContentOffset:CGPointMake(0, 0) animated:YES]; 
[tableView_ flashScrollIndicators]; 

但是,它不像您那樣爲ScrollIndicators設置動畫,點擊狀態欄滾動到頂部。

任何幫助將不勝感激,謝謝!

回答

1

嘗試像

-(void)doScroll{ 
    void (^scroll)(void) = ^{ 
     [contentTableView setContentOffset:CGPointMake(0, 0) animated:NO]; 
     [contentTableView flashScrollIndicators]; 
    }; 

    [UIView animateWithDuration:0.5 animations:scroll]; 
} 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    [self performSelector:@selector(doScroll) withObject:nil afterDelay:1]; 
} 
+0

感謝Friedgaad的ShouldStartLoadWithRequest委託方法,但表視圖細胞消失,而在這個方法中* _ *滾動。 – 2012-02-29 15:06:29

+1

我剛剛在桌面視圖上測試了這個,如果我的視圖正在動畫(這是我的情況翻轉),單元格會消失。所以我添加了一個performSelector:@selector afterDelay:然後顯示單元格。 – Friesgaard 2012-03-01 15:02:29

+0

謝謝,但我得到[ReadItLaterViewController滾動]:無法識別的選擇器加載我的應用程序後發送到實例0x8bee9a0。 看來我需要刪除「滾動」,但我無法在@interface中刪除這個void(^ scroll)(void)。 對不起,我對此有限知識,這個函數可能是C?而且,CGPointMake(0,3000)而不是(0,0)有任何理由嗎? – 2012-03-02 04:45:11

1

您是否嘗試過在組合使用-setContentOffset:animated與UIScrollViewDelegate方法- (void)scrollViewDidScrollToTop:和/或-(void)scrollViewDidEndScrollingAnimation:

您可能能夠將-flashScrollIndicators發送給其中一個,而不是依賴定時器,即使用-performSelector:withObject:afterDelay)。

+0

謝謝,我會檢查出來的! – 2012-05-01 04:36:32

0

試試這個在Web視圖

​​
相關問題