我收到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];
}
in uitable data source
- (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;
}
提前致谢
答案 0 :(得分:1)
如果您在头文件中有:
@property(nonatomic, strong)NSArray *nFragmentFilterItems;
你必须致电:
self.nFragmentFilterItems = [NSArray arrayWithObjects:@"Min", @"Max", nil];
您还必须在实现文件中综合您的属性:
@synthesize nFragmentFilterItems;
答案 1 :(得分:1)
请试试这个
nFragmentFilterItems = [[NSArray arrayWithObjects:@"Min",
@"Max", nil] retain];
韩国社交协会