2014-02-24 31 views
0

當下面的代碼運行時(一旦它進入方法),就會有幾秒的凍結。我甚至無法向上或向下滾動。我試圖通過使用塊刪除它,但即使下面的代碼仍然凍結。下面是代碼:prepareForSegue:在目標C上使用塊

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
dispatch_queue_t downloadQueu= dispatch_queue_create("downloader",NULL); 
dispatch_async(downloadQueu, ^{ 
    NSDictionary *placeDictionary = 
    [self.topPlaces objectAtIndex:self.tableView.indexPathForSelectedRow.row]; 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     [[segue destinationViewController] setPhotoList:[FlickrFetcher photosInPlace:placeDictionary 
                     maxResults:50] 
              withTitle:[[sender textLabel] text]]; 
    }); 
}); 
} 

回答

0

你可能想一次,而不是在每次調用這個方法創建調度隊列。另外請注意,您不能從後臺線程(即您的塊)使用indexPathForSelectedRow;你需要把它存儲在你方法中的一個變量中,外部的。除非您注意線程安全性,否則您可能也會遇到[topPlaces objectAtIndex:]的問題。