【发布时间】:2014-07-16 17:22:47
【问题描述】:
我创建一个像这样的饼图:
NSArray *n = [data allKeys];
long sc = [n count];
XYPieChart *pie = [[XYPieChart alloc] initWithFrame:CGRectMake(0, self.pieStart, 160, 220)];
[pie setDataSource:self];
[pie setDelegate:self];
[pie setStartPieAngle:M_PI_2];
[pie setAnimationSpeed:1.0];
[pie setLabelFont:[UIFont fontWithName:@"Helvetica Neue" size:11]];
[pie setLabelRadius:40];
[pie setShowPercentage:NO];
[pie setPieBackgroundColor:[UIColor colorWithWhite:0.95 alpha:1]];
[pie setPieCenter:CGPointMake(80, 100)];
[pie setUserInteractionEnabled:NO];
[pie setLabelShadowColor:[UIColor blackColor]];
pie.tag = tag;
pie.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UILabel *t = [[UILabel alloc] initWithFrame:CGRectMake(0, 2, 320, 21)];
t.textAlignment = NSTextAlignmentCenter;
[t setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:17]];
t.text = title;
UILabel *p = [[UILabel alloc] initWithFrame:CGRectMake(71, 90, 18, 18)];
p.text = @"%";
p.backgroundColor = [UIColor whiteColor];
p.textAlignment = NSTextAlignmentCenter;
[p setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:13]];
p.layer.cornerRadius = 9;
p.layer.masksToBounds = YES;
int vc = 35;
int lc = 31;
[pie addSubview:t];
[pie addSubview:p];
[self.myScroll addSubview:pie];
self.pieStart += 220;
[pie reloadData];
for(int i = 0; i < sc; i++){
UIView *cc = [[UIView alloc] initWithFrame:CGRectMake(162, vc, 9, 9)];
cc.backgroundColor = [self.sliceColors objectAtIndex:(i % self.sliceColors.count)];
[pie addSubview:cc];
UILabel *tl = [[UILabel alloc] initWithFrame:CGRectMake(180, lc, 134, 17)];
[tl setFont:[UIFont fontWithName:@"HelveticaNeue" size:10]];
tl.text = [self.ss objectAtIndex:i];
[pie addSubview:tl];
vc += 12;
lc += 12;
}
//NSLog(@"got here");
UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, pie.frame.size.height - 20, 320, 1)];
line.backgroundColor = [UIColor lightGrayColor];
[pie addSubview:line];
并尝试像这样设置自定义切片标签:
-(NSString *)pieChart:(XYPieChart *)pieChart textForSliceAtIndex:(NSUInteger)index
{
return [NSString stringWithFormat:@"%@", [self.slices objectAtIndex:index]];
}
但我得到了这个回报:
*** Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer bounds contains NaN: [-1.99794 0; 1.99794 nan]'
* 首先抛出调用栈: (0x1625012 0x144ae7e 0x1624deb 0x29fa75 0x29fd1e 0x2f6e6 0x2b54f 0x1378e 0xf0a8 0xe3a4 0x10ad417 0x10c6b24 0x107bd60 0x10c86ad 0xbf1d 0x6991c7 0x699232 0x6994da 0x6b08e5 0x6b09cb 0x6b0c76 0x6b0d71 0x6b189b 0x6b1e93 0x6b1a88 0xa0de63 0x9ffb99 0x9ffc14 0x145e705 0x5bb2c0 0x7f7a64 0x145e705 0x5bb2c0 0x5bb258 0x67c021 0x67c57f 0x67b6e8 0x5eacef 0x5eaf02 0x5c8d4a 0x5ba698 0x2adadf9 0x2adaad0 0x159abf5 0x159a962 0x15cbbb6 0x15caf44 0x15cae1b 0x2ad97e3 0x2ad9668 0x5b7ffc 0x43a6d 0x27fb701) libc++abi.dylib:终止调用抛出异常
到目前为止,我已经能够弄清楚当 [pie reloadData] 发生时会发生错误。
在 iOS7 上完美运行
是否有我没有应用的设置或者我做错了什么?
在我的上一个项目中,我也使用了 XYPieCharts,并且我也支持 iOS 6,唯一的区别是我在 IB 创建器中使用饼图而不是在代码中创建了 UIView。
任何帮助将不胜感激!
【问题讨论】:
标签: objective-c xcode inversion-of-control calayer