ブロックを介してコードを実行し、コードの実行中にインジケーターを表示できるカスタム インジケーターを作成しました。
コードが完成したら、2 番目の成功ブロックを呼び出して、インジケーターを非表示/削除します。
使用したいクラスのすべてのインジケーターをインスタンス化したくないので、インジケーター オブジェクトはシングルトンです。
ワークフロー:
- 指標の作成
 - インジケータを表示
 - コードブロックを実行
 - 実行成功ブロック
 - インジケータを非表示
 - スーパービューから削除
 - 共有インスタンスを無効化
 
この問題は、2 つのインジケーターを交互に使用すると発生します (例:ログイン後、データを更新)。
2 番目のインジケーターが表示されると、最初のインスタンスで hide メソッドが呼び出されます。そして、2 番目のインジケーターの間、インジケーター ビューはスーパービューから削除されます。
自分でスレッドロックを管理した経験がないのですが、使って解決しようと思ったの@synchronized(self)ですが、効果がないように見えますか?
+ (Indicator *)create
{
    if (!sharedIndicator)
    {
        sharedIndicator = [[Indicator alloc] initWithNibName:@"Indicator" bundle:nil];
    }
    return sharedIndicator;
}
+ (Indicator *)createWithDelegate:(id <IndicatorDelegate>)delegate 
                             message:(NSString *)message 
                              inView:(UIView *)parentView
{
    Indicator *indicator = [Indicator create];
    [indicator setDelegate:delegate];
    [indicator setMessage:message];
    [indicator setParentView:parentView];
    return indicator;
}
+ (void)showInView:(UIView *)view 
       withMessage:(NSString *)message 
           execute:(BOOL (^)(void))executeBlock 
          complete:(void (^)(BOOL success))completed
{
    Indicator *indicator = [Indicator createWithDelegate:nil message:message inView:view];
    [indicator show];
    __block BOOL success = NO;
    dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^
    {    
        success = executeBlock();
        dispatch_async(dispatch_get_main_queue(), ^
        {
            completed(success);
            [indicator hide];
        });
    });
}