2014-09-06 91 views
2

我在我的應用程序中有一個奇怪的圖形故障,當我使用刷卡回到以前的視圖。導航欄故障時使用iOS 7刷卡導航

當我正常滑動並完成滑動手勢時,每項工作都可以正常工作。

當我取消滑動手勢時,即:開始手勢,然後沿相反方向移動手指以停止手勢並保持當前視圖。

我得到的故障如果我回到前一個屏幕,該視圖的barbutton項目與前一個視圖的barbutton項目重疊。

截圖: 起點:enter image description here

刷卡回退姿勢和完整的姿態,去以前的觀點,正常工作:enter image description here

刷卡回退姿勢和取消手勢,從而留在當前屏幕上,然後去回到前一個屏幕,文本按鈕重疊:enter image description here

當強制退出應用程序並重新啓動它時,此圖形故障僅消失。但是,當然,如果你再次挑起毛刺,它又會出現。

希望有一些開發者有同樣的問題。

編輯,問題的原因是以下代碼:

- (void)resetCacheAndRefreshTableAnimated:(BOOL)animated { 
    [NSFetchedResultsController deleteCacheWithName:kCDFollowedCacheName]; 
    [self setSortDescriptorsForFetchRequest:self.fetchedResultsController.fetchRequest]; 
    NSError *error = nil; 
    [self.fetchedResultsController performFetch:&error]; 
    [self.tableView reloadData]; 
} 

這種方法被稱爲在viewWillAppear中。當方法調用被刪除時,問題就會消失。任何想法?

+0

請張貼一些代碼。我可以想象的是,您可能沒有清除移動的視圖,所以即使您在移動中取消了手勢,已移動的視圖也不會重置。 – 2014-09-06 14:55:08

回答

1

基於Vikram的回覆和StackOverflow的另一個問題進行管理。

所以問題是[self.tableView reloadData]被稱爲ViewWillAppear。 但刷卡取消時不應重新加載tableview。

此代碼防止刷卡時被取消重裝:

id <UIViewControllerTransitionCoordinator> tc = self.transitionCoordinator; 
if (tc && [tc initiallyInteractive]) 
{ 
    [tc notifyWhenInteractionEndsUsingBlock: 
    ^(id<UIViewControllerTransitionCoordinatorContext> context) 
    { 
     if (![context isCancelled]) 
      // not cancelled, do it 
      [self resetCacheAndRefreshTableAnimated:YES]; // this will clear the CoreData cache and forces a reload 
    }]; 
} 
else // not interactive, do it 
    [self resetCacheAndRefreshTableAnimated:YES];  // this will clear the CoreData cache and forces a reload 
0

也許您可能未清除移動的視圖,因此即使您在移動過程中取消了手勢,已移動的視圖也不會重置。

+0

謝謝,我發現這個類似的問題:http://stackoverflow.com/questions/23261304/navigation-bar-title-bug-with-interactivepopgesturerecognizer。如何識別手勢何時取消? – edwardmp 2014-09-06 15:05:57

+0

發現問題的來源,在取消視圖控制器的ViewWillAppear中,這行代碼導致了這個問題:'[self resetCacheAndRefreshTableAnimated:YES];'刪除它修復了問題。 – edwardmp 2014-09-06 15:16:49