Question

Hi I am working on customPageControl. It is working fine on iOS 6 but app crashes on iOS 7. the detailed Scenario is as follow:

I am using a customPageControl file in my project. For detailed CustomPageControl you can go through this link. In iOS 6 [self.subviews objectAtIndex: 1] returns UIImageView but in iOS 7 it returns UIView. And I am using

UIImageView * imageView = [self.subviews objectAtIndex: 1];
imageView.image = [UIImage <SomeImage>];

in iOS 7 it take imageView as UIView and give exception that unrecoganised Selector sent.

Please give me some direction.

Was it helpful?

Solution

I have found a solution for this problem. I know it is not the way but Sure that it works till iOS 8 will be launched in the market.

Reason for Crash:

in iOS 7 [self.subViews objectAtIndex: i] returns UIView Instead of UIImageView and setImage is not the property of UIView and the app crashes. I solve my problem using this following code.

Check Whether the subview is UIView(for iOS7) or UIImageView(for iOS6 or earlier). And If it is UIView I am going to add UIImageView as subview on that view and voila its working and not crash..!!

-(void) updateDots
{
    for (int i = 0; i < [self.subviews count]; i++)
    {
        UIImageView * dot = [self imageViewForSubview:  [self.subviews objectAtIndex: i]];
        if (i == self.currentPage) dot.image = activeImage;
        else dot.image = inactiveImage;
    }
}
 - (UIImageView *) imageViewForSubview: (UIView *) view
{
    UIImageView * dot = nil;
    if ([view isKindOfClass: [UIView class]])
    {
        for (UIView* subview in view.subviews)
        {
            if ([subview isKindOfClass:[UIImageView class]])
            {
                dot = (UIImageView *)subview;
                break;
            }
        }
        if (dot == nil)
        {
            dot = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, view.frame.size.width, view.frame.size.height)];
            [view addSubview:dot];
        }
    }
    else
    {
        dot = (UIImageView *) view;
    }

    return dot;
}

Hope this solve ur issue too for iOS7. and If Anypone find the optimal solution for that please comment. :)

Happy coding

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top