我收到 NSArray 的 EXC_BAD_ACCESS 错误。还有其他阵列,它们工作正常。我在 viewDidLoad 中初始化了数组。每当我从不同的块访问它时,我都会收到错误消息。但是这个数组是在头文件中定义的。ARC 已开启。这是我的代码
头文件.h
@interface PopoverViewController : UITableViewController
{
NSArray *typeFilterItem;
NSArray *changeFilterItem;
NSArray *nFragmentFilterItems;
}
.m 文件
- (void)viewDidLoad
{
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations.
// self.clearsSelectionOnViewWillAppear = NO;
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem;
// set section
typeFilterItem = [NSArray arrayWithObjects:@"All",
@"Type-1",
@"Type-2",
@"Type-3", nil];
changeFilterItem = [NSArray arrayWithObjects:@"All",
@"Static Change",
@"Consistent Change",
@"Inconsistent Change", nil];
nFragmentFilterItems = [NSArray arrayWithObjects:@"Min",
@"Max", nil]; // this is the array causing problem
NSLog(@"count: %d", nFragmentFilterItems.count); // here its ok
// set filters
[self setAllTypeFilers];
[self setAllChangePatternFilters];
}
在合适的数据源中
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
/******* getting error at this line *****/
NSLog(@"count: %d", nFragmentFilterItems.count);
if (section == 0) {
return typeFilterItem.count;
} else if (section == 1) {
return changeFilterItem.count;
} else if (section == 2) {
return 2;
} else if (section == 3) {
return 1;
}
return 0;
}
提前致谢