检查iOS 7中的类

时间:2013-10-05 07:54:34

标签: iphone objective-c ios7

我正在将一个应用程序更新到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];



}

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

提前致谢。

2 个答案:

答案 0 :(得分: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)];
                        }
                    }
                }
               }

答案 1 :(得分: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 
            }
        }
    }
}
}