-1

我正在将一个应用程序更新到 iOS 6 到 iOS 7。但我遇到了关于类的问题。在 iOS 6 中显示类名自定义按钮,但在 iOS 7 中显示 _UITextContainerView。

    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)];
                    }
                }
            }
           }

更新

pragma mark - 文字段落 iPhone

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

我无法找到为什么它在任何对象的类名中显示不同。此外,我在谷歌上没有发现任何关于此的问题。如果有人对此有任何想法,请帮助我。

提前致谢。

4

2 回答 2

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)];
                        }
                    }
                }
               }
于 2013-10-06T09:17:56.493 回答
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 
            }
        }
    }
}
}
于 2013-10-06T08:17:10.293 回答