Ios 为什么自定义drawRect未在6.1模拟器中显示?

Ios 为什么自定义drawRect未在6.1模拟器中显示?,ios,ios-simulator,drawrect,Ios,Ios Simulator,Drawrect,UICollectionViewCell中有一个UIView子类(ThumbView)。以下代码在iOS 7模拟器中运行良好: - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { static NSString *identifier = @"Cell"; UICollectionV

UICollectionViewCell
中有一个UIView子类(
ThumbView
)。以下代码在iOS 7模拟器中运行良好:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    ThumbView *thumbView = (ThumbView *)[cell viewWithTag:1];
    [thumbView setNeedsDisplay];
    return cell;
}

但是,在iOS 6版本的模拟器中:

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"Cell";
    UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
    ThumbView *thumbView = (ThumbView *)[cell viewWithTag:1];
    [thumbView setNeedsDisplay];
    return cell;
}
网格都消失了:

我在ThumbView的
drawRect
中放置了一个
NSLog
,以确保调用了
drawRect

怎么了

  • Xcode版本5.0(5A1412)
  • iOS模拟器7.0版(463.9.4)
更新(图纸代码):

-(void)drawRect:(CGRect)rect
{
NSLog(@“%s”,函数);
[自绘制网格:rect];
}
-(void)drawGrid:(CGRect)rect
{
CGFloat margin=自身保证金;
CGFloat线宽=2.0;
CGContextRef context=UIGraphicsGetCurrentContext();
CGRect gridRect=CGRectInset(rect,margin,margin);
对于(NSInteger i=1;i<9;i++){
CGFloat h=gridRect.size.height/9;
cGy=i*h;
CGContextMoveToPoint(上下文、边距、y+边距);
CGContextAddLineToPoint(上下文,gridRect.size.width+边距,y+边距);
CGContextSetLineWidth(上下文,线宽/4.0);
如果(i==3 | | i==6){
CGContextSetStrokeColorWithColor(上下文,UIColor.darkGrayColor.CGColor);
}否则{
CGContextSetStrokeColorWithColor(上下文,UIColor.lightGrayColor.CGColor);
}
CGContextStrokePath(上下文);
}
对于(NSInteger i=1;i<9;i++){
CGFloat w=gridRect.size.width/9;
CGFloat x=i*w;
CGContextMoveToPoint(上下文,x+边距,边距);
CGContextAddLineToPoint(上下文、x+边距、gridRect.size.height+边距);
CGContextSetLineWidth(上下文,线宽/4.0);
如果(i==3 | | i==6){
CGContextSetStrokeColorWithColor(上下文,UIColor.darkGrayColor.CGColor);
}否则{
CGContextSetStrokeColorWithColor(上下文,UIColor.lightGrayColor.CGColor);
}
CGContextStrokePath(上下文);
}
CGFloat frameWidth=线宽*2.0;
CGRect frameRect=CGRectInset(rect,0.0,0.0);
如果(UI\u USER\u INTERFACE\u IDIOM()==UIUserInterfaceIdiomPad)frameWidth=lineWidth*2.0;
CGContextSetLineWidth(上下文,帧宽度);
CGContextSetStrokeColorWithColor(上下文,UIColor.darkGrayColor.CGColor);
CGContextStrokeRect(上下文,frameRect);
}

您是否检查过在iOS6中没有在白色背景上绘制白线?(例如,如果您在iOS7中使用tintColor…

而没有看到代码,则很难说。当我在视网膜模拟器和非视网膜模拟器上运行代码时,我看到过类似的情况,并且没有正确地解释刻度差异。

你的问题中是否有拼写错误,因为方法名称是
drawRect:
?拼写错误只存在于问题中,已修复。谢谢。尽管iOS 7即将发布,但它仍处于NDA之下,因此在此之前您不太可能得到一个好的答案。您如何将ThumbView添加为UICollectionViewCell的子视图?您能否发布一些绘图代码,以便我们可以查看一些资料并查看问题所在?