NDM*_*DEV 11 objective-c uipagecontrol ios7
在我努力升级我的应用程序以支持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];
}
Run Code Online (Sandbox Code Playgroud)

现在在IOS7中我收到以下错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView setImage:]: unrecognized selector sent to instance 0xe02ef00'
Run Code Online (Sandbox Code Playgroud)
并且在调查之后我明白以下代码会导致错误:
UIImageView* dot = [self.subviews objectAtIndex:i];
if (i == self.currentPage) dot.image = activeImage;
else dot.image = inactiveImage;
Run Code Online (Sandbox Code Playgroud)
我检查了子视图,发现它是UIView而不是UIImageView.可能苹果改变了一些东
知道怎么解决吗?
Tho*_*sen 38
看起来他们将子视图更改为标准UIViews.我设法解决这个问题:
for (int i = 0; i < [self.subviews count]; i++)
{
UIView* dotView = [self.subviews objectAtIndex:i];
UIImageView* dot = nil;
for (UIView* subview in dotView.subviews)
{
if ([subview isKindOfClass:[UIImageView class]])
{
dot = (UIImageView*)subview;
break;
}
}
if (dot == nil)
{
dot = [[UIImageView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, dotView.frame.size.width, dotView.frame.size.height)];
[dotView addSubview:dot];
}
if (i == self.currentPage)
{
if(self.activeImage)
dot.image = activeImage;
}
else
{
if (self.inactiveImage)
dot.image = inactiveImage;
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8636 次 |
| 最近记录: |