2012-10-10 111 views
1

在自定義的tableview細胞按下一個按鈕後叫我執行非同步操作,並在選擇回撥電話:DidDisappear從其他線程,並與延遲

[self performSegueWithIdentifier:SEGUE_PURCHASE_SEGUE sender:self];

所以接下來的回調所謂:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 
} 

,我可以在日誌中看到,新屏幕的viewDidLoad and viewWillAppear方法已經被調用,但下一屏幕將顯示僅在這之後幾秒鐘。

這裏有什麼問題?

CODE:

-(void) moveToPurchaseScreen{ 

    NSLog(@"view1 moveToPurchaseScreen"); 

    [self performSegueWithIdentifier:SEGUE_PURCHASE_SEGUE sender:self]; 
} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{ 

    NSLog(@"view1 prepareForSegue"); 
//  
// BSPurchaseViewController *purchaseViewController = [segue destinationViewController];  
// purchaseViewController.pngImage = [BSSharedObject getInstance].createdImage; 
//// [[BSPopupManager getInstance]closeWaitingPopup]; 
//  
//  
//  NSLog(@"2"); 
} 

-(void)viewDidDisappear:(BOOL)animated{ 
    NSLog(@"view1 DidDisappear"); 
} 

2012-10-10 21:51:15.644 BarneyShop[4961:11603] view1 moveToPurchaseScreen 
2012-10-10 21:51:15.646 BarneyShop[4961:11603] view1 prepareForSegue 
2012-10-10 21:51:15.647 BarneyShop[4961:11603] view2 viewDidLoad 
2012-10-10 21:51:15.648 BarneyShop[4961:11603] view2 viewWillAppear 
2012-10-10 21:51:23.812 BarneyShop[4961:f803] view1 DidDisappear 

編輯2:

[purchase initPurchase: self withSelector:@selector(moveToPurchaseScreen)andProduct:product]; 


-(void) initPurchase:(id)object withSelector:(SEL)selector andProduct:(Product *)product{ 

    [operationQueue cancelAllOperations]; 

    NSInvocationOperation *downloadImageOperation = [[NSInvocationOperation alloc] initWithTarget:[BSImageDownloader getInstance] selector:@selector(downloadImageSync:) object:URL_DOWNLOAD_IMAGE]; 

    NSInvocationOperation *createImageOperation = [[NSInvocationOperation alloc] initWithTarget:[BSImageCreator getInstance] selector:@selector(createImage:) object:product]; 

    NSInvocationOperation *saveImageOperation = [[NSInvocationOperation alloc] initWithTarget:[BSImageSaver getInstance] selector:@selector(saveImageAsPng:) object:nil]; 

    NSInvocationOperation *callbackOperation = [[NSInvocationOperation alloc] initWithTarget:object selector:selector object:nil]; 

    [createImageOperation addDependency:downloadImageOperation]; 
    [saveImageOperation addDependency:createImageOperation]; 
    [callbackOperation addDependency:saveImageOperation]; 

    [operationQueue addOperation:downloadImageOperation]; 
    [operationQueue addOperation:createImageOperation]; 
    [operationQueue addOperation:saveImageOperation]; 
    [operationQueue addOperation:callbackOperation];  

} 
+0

什麼的 「異步操作」 執行?我們可以看到代碼嗎? – Tim

+0

我看到viewDidLoad1和viewWillAppear之間的3ms差異。你談論的那幾秒鐘在哪裏? –

+0

我編輯了代碼,請參閱。 – pvllnspk

回答

1

在你的方法:

-(void)viewDidDisappear:(BOOL)animated { 

    [super viewDidDisappear:animated]; // <-- Try adding this. 

    NSLog(@"view1 DidDisappear"); 
} 

讓我知道這將加快你的進程。我也注意到這個方法被從另一個線程調用。你是否手動調用它?

編輯

試試這個還有:

-(void) moveToPurchaseScreen{ 

    NSLog(@"view1 moveToPurchaseScreen"); 

    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self performSegueWithIdentifier:SEGUE_PURCHASE_SEGUE sender:self]; 
    }); 
} 
+0

相同的結果: 2012年10月10日21:59:34.669 BarneyShop [5198:17107]視圖2 viewWillAppear中 2012年10月10日21:59:42.297 BarneyShop [5198:F803]廠景DidDisappear – pvllnspk

+0

我也不是什麼得到的是爲什麼這個方法被從不同的線程調用... –

+0

請參閱編輯2 – pvllnspk