Custom UIPageviewControl的子视图在ios7中返回UIView,在ios6中返回UIImageView [英] subviews of Custom UIPageviewControl return UIView in ios7 but UIImageView in ios6
问题描述
您好我正在使用customPageControl。它在iOS 6上工作正常,但iOS 7上的应用程序崩溃。详细的场景如下:
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:
我在我的项目中使用了customPageControl文件。有关详细的CustomPageControl,您可以通过此 链接强> 。在iOS 6中 [self.subviews objectAtIndex:1]
返回 UIImageView
但在iOS 7中它返回的UIView
。我正在使用
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>];
在iOS 7中它将imageView视为 UIView
并给出未经认可的Selector发送的异常。
in iOS 7 it take imageView as UIView
and give exception that unrecoganised Selector sent.
请给我一些指示。
推荐答案
我找到了一个这个问题的解决方案。我知道这不是方法,但确定它会起作用,直到iOS 8将在市场上推出。
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.
崩溃的原因:
[self.subViews objectAtIndex:i]
返回 UIView
而不是 UIImageView
和 setImage
不是 UIView
的属性,应用程序崩溃了。我使用以下代码解决了我的问题。
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.
检查子视图是否为 UIView
(适用于iOS7)或 UIImageView
(适用于iOS6或更早版本)。如果它是 UIView
我将在该视图上添加 UIImageView
作为子视图,并告知其工作而不是崩溃。 。!!
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;
}
希望这也解决了iOS7的问题。如果Anypone找到最佳解决方案,请发表评论。 :)
Hope this solve ur issue too for iOS7. and If Anypone find the optimal solution for that please comment. :)
快乐编码
这篇关于Custom UIPageviewControl的子视图在ios7中返回UIView,在ios6中返回UIImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!