我尝试查找其他问题,但找不到任何匹配的内容,所以这里是:
我正在尝试在表格视图中显示文本,所以我使用了这段代码:
// StockData is an object I created and it pulls information from Yahoo APIs based on
// a stock ticker stored in NSString *heading
NSArray* tickerValues = [heading componentsSeparatedByString:@" "];
StockData *chosenStock = [[StockData alloc] initWithContents:[tickerValues objectAtIndex:0]];
[chosenStock getData];
// Set up the cell...
NSDictionary *tempDict = [chosenStock values];
NSArray *tempArr = [tempDict allValues];
cell.textLabel.text = [tempArr objectAtIndex:indexPath.row];
return cell;
这都在 cellForRowAtIndexPath 下
当我尝试释放 selectedStock 对象时,虽然我收到此错误:[CFDictionary release]: message sent to deallocated instance 0x434d3d0
我尝试使用 NSZombieEnabled 和 Build and Analyze 来检测问题,但到目前为止没有运气。我什至用 NSLog 评论代码的点点滴滴,但没有运气。我将在下面发布 StockData 的代码。据我所知,在我发布之前有些东西正在被释放,但我不确定如何。我在代码中唯一发布的地方是在 dealloc 方法调用下。
这是 StockData 代码:
// StockData contains all stock information pulled in through Yahoo! to be displayed
@implementation StockData
@synthesize ticker, values;
- (id) initWithContents: (NSString *)newName {
if(self = [super init]){
ticker = newName;
}
return self;
}
- (void) getData {
NSURL *url = [NSURL URLWithString: [NSString stringWithFormat:@"http://download.finance.yahoo.com/d/quotes.csv?s=%@&f=%@&e=.csv", ticker, @"chgvj1"]];
NSError *error;
NSURLResponse *response;
NSURLRequest *request = [NSURLRequest requestWithURL:url];
NSData *stockData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
if(stockData) {
NSString *tempStr = [[NSString alloc] initWithData:stockData encoding:NSASCIIStringEncoding];
NSArray *receivedValuesArr = [tempStr componentsSeparatedByString:@","];
[tempStr release];
values = [NSDictionary dictionaryWithObjects:receivedValuesArr forKeys:[@"change, high, low, volume, market" componentsSeparatedByString:@", "]];
} else {
NSLog(@"Connection failed: %@", error);
}
}
- (void)dealloc {
[ticker release];
[values release];
[super dealloc];
NSLog(@"Release took place fine");
}
@end