0

코드를 실행하고 코드가 실행되는 동안 표시기를 표시 할 수있는 사용자 지정 표시기를 만들었습니다. 코드가 나는 두 번째 성공 블록 및 숨기기를 호출 완료되면 Objective-c 맞춤 표시기 잠금 공유 인스턴스

/표시기를 제거합니다. 내가 그들을 사용하려는 클래스의 모든 표시를 인스턴스화 할하지 말자 때문에

는 표시 객체는 싱글이다.

워크 플로 :

  1. 표시 표시
  2. 실행 코드 블록
  3. 실행 성공 블록
  4. 숨기기 표시
  5. 는 수퍼에서 제거 표시 만들기
  6. 무효가 공유 (: 로그인을 한 후, 데이터를 새로 예) I 서로 후 2 개 지표를 사용할 때의 자세

문제가 발생한다. 제 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]; 
     }); 
    }); 
} 
+0

변수'success'는 첫 번째 블록 내부에서 (__block이 아닌) 일반 변수로 선언되어야합니다 – newacct

답변

0

표시기를 표시 할 때마다 sharedInstance와 연결된 이후 동일한보기가 표시됩니다.