1

在自定义表格视图单元格中按下按钮后,我执行异步操作并在选择器回调调用中:

[self performSegueWithIdentifier:SEGUE_PURCHASE_SEGUE sender:self];

所以调用下一个回调:

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

我可以在日志中看到新屏幕的viewDidLoad and viewWillAppear方法已经被调用,但是下一个屏幕只会在这之后的几秒钟内显示。

这里可能有什么问题?

代码:

-(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];    

}
4

1 回答 1

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];
    });
}
于 2012-10-10T18:58:14.710 回答