在我努力升级我的应用程序以支持 IOS7 时,我发现它UIPageControl
不支持UIImageView
. 他们改变了它。
我将其子类化UIPageControl
以放置自定义圆圈而不是常规圆圈(附上示例)
我的课是:
- (id)initWithFrame:(CGRect)frame
{
// if the super init was successfull the overide begins.
if ((self = [super initWithFrame:frame]))
{
// allocate two bakground images, one as the active page and the other as the inactive
activeImage = [UIImage imageNamed:@"active_page_image.png"];
inactiveImage = [UIImage imageNamed:@"inactive_page_image.png"];
}
return self;
}
// Update the background images to be placed at the right position
-(void) updateDots
{
for (int i = 0; i < [self.subviews count]; i++)
{
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) dot.image = activeImage;
else dot.image = inactiveImage;
}
}
// overide the setCurrentPage
-(void) setCurrentPage:(NSInteger)page
{
[super setCurrentPage:page];
[self updateDots];
}
现在在 IOS7 中出现以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0xe02ef00'
经过调查,我了解到以下代码会导致错误:
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) dot.image = activeImage;
else dot.image = inactiveImage;
我检查了子视图,发现它是 UIView 而不是 UIImageView。可能苹果改变了一些东西。
知道如何解决吗?