私はObjective-Cのディスパッチ機構について頭を下ろそうとしています。しかし、成功しないでください。ディスパッチを理解しようとしています
- (void)downloadImage
{
NSString * URLString= @"http://www.something.com";
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
NSURL *imageURL = [NSURL URLWithString:fullURL];
NSData *imageData = [NSData dataWithContentsOfURL:imageURL];
theImportant.image = [UIImage imageWithData:imageData];
dispatch_sync(dispatch_get_main_queue(), ^{
stopAnimate=true;
[self MoveToPosition:myView.center];
});
});
}
と::
-(void)MoveToPosition:(CGPoint)position{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[UIView animateWithDuration:1.5
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut |UIViewAnimationOptionBeginFromCurrentState
animations:^{
myView.center=position;
}
completion:^(BOOL finished){
if (stopAnimate){
//do Nothing
} else if (someFlag){
[self downloadImage];
}
}
];
}
ので、第一の方法は、二によって呼び出され、今度は最初に呼び出している
は、私はこれらの2つの方法があります。
これは何とかImportant.imageが表示されていないことを除いて、すべて問題なく動作しています。
私はdownloadImageの
dispatch_sync
ブロック内
theImportant.image = [UIImage imageWithData:imageData];
を移動すると、アニメーションが予期しない方法で行動を開始します。
私は派遣を完全には理解していないことを認識していますが、あなたの洞察が私の知恵を伸ばすことを願っています。
theImportantは
@property(強い、原子)IBOutlet UIImageView * theImportantとして定義されます。
私の質問は簡単です:なぜ私のtheImportant.imageは表示されません。
私たちがこの問題を解決するためには、 'aMethodThatNeedsVERYIMPORTANTImageToBeInPlaceInTime'メソッド(もちろん実際の方法)と' VERIMPORTANT'の詳細とそれがどのようになっているかについての詳細を記述する必要がありますセットアップ。 – rmaddy
他のメソッドを追加しました – Sjakelien
あなたのコードが何をしているのかはまだまだ明確ではなく、まさに「予期しない動作をする」とはどういう意味ですか。'重要なのはどのようなものですか?そのタイプは何ですか? –