2013-10-05 3 views
-1

iOS 6에서 iOS 7까지 하나의 앱을 업데이트하고 있습니다. 그러나 클래스와 관련하여 문제가 발생합니다. iOS 6에서는 클래스 이름 사용자 정의 버튼을 표시하지만 iOS 7에서는 _UITextContainerView를 표시합니다.iOS 7에서 클래스의 종류를 확인하십시오.

for (UIView *subView in textViewButton.subviews) 
     { 
      NSLog(@"yourObject is a: %@", [subView class]); 
      @autoreleasepool 
      { 
       if([subView isKindOfClass:[CustomButton class]]) 
       { 
        CustomButton *button = (CustomButton*)subView; 
        button.backgroundColor = [UIColor redColor]; 

        [button setType:kButtonTypeQuestion]; 
        button.titleLabel.font = kFontForContentPhone; 

        if (button.tag == 62254 || button.tag == 62263) 
        { 
         CGRect tempFrame = button.frame; 
         tempFrame.origin.x = button.frame.origin.x - 3.0f; 


         button.frame = tempFrame; 
        } 
        if (self.soundFile != nil) 
        { 

         CGRect tempFrame = button.frame; 
         tempFrame.size.width = button.frame.size.width + 28.0f; 
         button.frame = tempFrame; 
         [button setContentEdgeInsets:UIEdgeInsetsMake(5.0f, 30.0f, 5.0f, 10.0f)]; 
        } 
       } 
      } 
      } 

업데이트

프라그 마크 - 텍스트 단락 아이폰

self.questionScrollView = [[CustomScrollView alloc] initWithFrame:CGRectMake(0, currentYPosition, self.frame.size.width, self.frame.size.height - currentYPosition - 60.0f)]; 
    self.questionScrollView.showsVerticalScrollIndicator = NO; 

    self.questionsContainer = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.questionScrollView.frame.size.width, self.questionScrollView.frame.size.height)]; 
    currentYPosition = 0; 

     for (Question *question in self.questions) 
     { 
      @autoreleasepool 
      { 
       self.ttmItem = [[TapToMoveItem alloc] initWithFrame:CGRectMake(0, currentYPosition, self.frame.size.width, self.frame.size.height)]; 
       self.ttmItem.ttmDelegate = self; 
       self.ttmItem.variant = self.exercise.variant; 
       ttmItem.x_Position = question.x_position; 
       ttmItem.y_Position = question.y_position; 

       if ([question.sound_file length] > 0 || question.sound_file != nil) 
        self.ttmItem.hasAudio = YES; 
       else 
        self.ttmItem.hasAudio = NO; 

       if ([kPrefixImage isEqualToString:@"preint_"] && ([self.exercise.exercise_id integerValue] == 54 || [self.exercise.exercise_id integerValue] == 91)) { 
        ttmItem.soundFile = self.exercise.header_title; 
       } 

       self.ttmItem.prefix = question.prefix; 
       self.ttmItem.text = question.text; 
       self.ttmItem.longestPrefix = longestPrefix; 

       self.ttmItem.longestAnswer = longestAnswer; 
       self.ttmItem.buttonWidth = sizeForButton.width; 

       //get and set answers 
       ttmItem.answers = [self.answers objectForKey:question.question_id]; 

       [self.ttmItem createForPhone]; 

       [self.questionsContainer addSubview:self.ttmItem]; 

       currentYPosition += ttmItem.frame.size.height + SPACE_BET_VIEWS; 

       //   itemHeight = ttmItem.frame.size.height; //hack 
       //   itemWidth = ttmItem.frame.size.width; 

       ttmCount++; 


       if ([ttmItem.arrayOfTextViewButtons count] > 0) { 
        [dictionaryOfItemButtons setObject:ttmItem.arrayOfTextViewButtons forKey:question.question_id]; 
       } 

      } 

     } 


    self.questionsContainer.frame = CGRectMake(questionsContainer.frame.origin.x, questionsContainer.frame.origin.y, questionsContainer.frame.size.width, currentYPosition); 

    [self.questionScrollView setContentSize:self.questionsContainer.frame.size]; 

    [self.questionScrollView addSubview:self.questionsContainer]; 
    [self addSubview:self.questionScrollView]; 
    [self setScrollEnabled:NO]; 



} 

내가 찾을 수없는 나는 그것이 어떤 객체의 클래스 이름의 다른 보여주는 이유. 또한 나는 구글에 관한 어떤 문제도 발견하지 못했다. 누군가가 이것에 대한 생각을 갖고 있다면 저를 도우십시오.

미리 감사드립니다.

+0

문제는 isKindOfClass''하지입니다, 그것은 사실이다 클래스가 다르다는 것. 보기가 어떻게 생성되는지 보여줍니다. – trojanfoe

+0

@ 트로이 목마 업데이트 된 코드를 확인하십시오 –

+0

새 코드에서'self.textViewButton'에 하위 뷰가 추가되지 않습니다. – trojanfoe

답변

2

나는이 일을하여이 문제를 해결 한 :

for (UIView *subView in textViewButton.textInputView.subviews) 
      { 
       // const char* className = class_getName([yourObject class]); 
       NSLog(@"yourObject is a: %@", [subView class]); 
       @autoreleasepool 
       { 
        if([subView isKindOfClass:[CustomButton class]]) 
        { 
         CustomButton *button = (CustomButton*)subView; 
         button.backgroundColor = [UIColor clearColor]; 

         [button setType:kButtonTypeQuestion]; 

         button.titleLabel.font = kFontForContentPhone; 

         if (button.tag == 62254 || button.tag == 62263) 
         { 
          CGRect tempFrame = button.frame; 
          tempFrame.origin.x = button.frame.origin.x - 3.0f; 


          button.frame = tempFrame; 
         } 
         if (self.soundFile != nil) 
         { 

          CGRect tempFrame = button.frame; 
          tempFrame.size.width = button.frame.size.width + 28.0f; 
          button.frame = tempFrame; 
          [button setContentEdgeInsets:UIEdgeInsetsMake(5.0f, 30.0f, 5.0f, 10.0f)]; 
         } 
        } 
       } 
       } 
+0

다시 아주 좋은 대답을 ....... –

0

개체를 찾을 때까지 모든 하위 뷰를 반복합니다. 당신은 객체 출구에게 불필요한 자원을 절약 할 수있는 루프를 찾을 일이 있으면

for (UIView *subView in textViewButton.subviews) 
{ 
    NSLog(@"yourObject is a: %@", [subView class]); 
    @autoreleasepool 
    { 
     if([subView isKindOfClass:[CustomButton class]]) 
     { 
      CustomButton *button = (CustomButton*)subView; 
      button.backgroundColor = [UIColor redColor]; 

     [button setType:kButtonTypeQuestion]; 
     button.titleLabel.font = kFontForContentPhone; 

     if (button.tag == 62254 || button.tag == 62263) 
     { 
      CGRect tempFrame = button.frame; 
      tempFrame.origin.x = button.frame.origin.x - 3.0f; 


      button.frame = tempFrame; 
     } 
     if (self.soundFile != nil) 
     { 
      CGRect tempFrame = button.frame; 
      tempFrame.size.width = button.frame.size.width + 28.0f; 
      button.frame = tempFrame; 
      [button setContentEdgeInsets:UIEdgeInsetsMake(5.0f, 30.0f, 5.0f, 10.0f)]; 
     } 

    } 
    else if ([subView isKindOfClass:NSClassFromString(@"_UITextContainerView")]) { 
     // do a another loop 
     for (UIView *innerSubViews in subView.subviews) { 
      if([subView isKindOfClass:[CustomButton class]]) 
      { 
       // call your custom button method here 
       break; // stop inner loop 
      } 
     } 
    } 
} 
} 
관련 문제