【发布时间】:2011-02-17 06:16:42
【问题描述】:
在我的 iPhone 应用程序中,我添加了核心情节。
如果我通过for 循环随机创建值,它工作正常(下面代码中的注释行)
当我尝试将一组值作为绘图点传递时,应用程序崩溃了。
可能出了什么问题?
我尝试调试,但从数组中正确获取了值。应用崩溃时,控制台中也没有错误消息。
下面是传递数组值的代码
代码:
- (void)generateData
{
NSArray *A = [[NSArray alloc] initWithObjects:@"1000",@"2000",@"1100",@"4000",nil];
NSArray *B = [[NSArray alloc] initWithObjects:@"1100",@"2200",@"3300",@"4400",nil];
if (plotData == nil)
{
NSMutableArray *contentArray = [NSMutableArray arrayWithCapacity:100];
for (NSUInteger i = 0; i < 4; i++)
{
id x = (NSNumber *)[NSNumber numberWithUnsignedInteger:[[A objectAtIndex:i] intValue]];
id y = (NSNumber *)[NSNumber numberWithUnsignedInteger:[[B objectAtIndex:i] intValue]];
// id x = [NSDecimalNumber numberWithDouble:1.0 + i * 0.05];
// id y = [NSDecimalNumber numberWithDouble:1.2 * rand()/(double)RAND_MAX + 0.5];
[contentArray addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:x, @"x", y, @"y", nil]];
}
plotData = [contentArray retain];
}
}
【问题讨论】:
-
我不知道你期望什么,但除了丑陋的代码和泄漏之外,这段代码没有任何问题。该代码完全符合我的想法。在其他位置查找您的错误。
标签: iphone cocoa-touch nsarray core-plot