我使用NSArray填充UITableView時遇到問題。我確信我正在做一些愚蠢的事情,但我無法弄清楚。當我嘗試做一個簡單的計數時,我得到了EXC_BAD_ACCESS,我知道這是因爲我試圖從不存在的內存位置讀取數據。NSArray導致EXC_BAD_ACCESS
我.h文件中有這樣的:
@interface AnalysisViewController : UITableViewController
{
StatsData *statsData;
NSArray *SectionCellLabels;
}
我的.m有這樣的:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
NSLog(@"AnalysisViewController:viewWillAppear");
// Step 1 - Create the labels array
SectionCellLabels = [NSArray arrayWithObjects:@"analysis 1",
@"analysis 2",
@"analysis 3", nil];
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"AnalysisViewController:cellForRowAtIndexPath");
// Check for reusable cell first, use that if it exists
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"UITableViewCell"];
// If there is no reusable cell of this type, create a new one
if (!cell) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:@"UITableViewCell"] autorelease];
}
/******* The line of code below causes the EXC_BAD_ACCESS error *********/
NSLog(@"%d",[SectionCellLabels count]);
return cell;
}
任何幫助極大的讚賞。
邁克
非常感謝。我真的很困難於Objective C的保留/釋放內存管理方面。你怎麼知道汽車什麼時候發佈,什麼時候沒有發佈? :-s – hydev 2011-02-06 17:32:07