iphone - 获取 NSArray 的 EXC_BAD_ACCESS

标签 iphone objective-c ios uitableview nsarray

我收到 NSArray 的 EXC_BAD_ACCESS 错误。还有其他阵列,它们工作正常。我在 viewDidLoad 中初始化了数组。每当我从不同的 block 访问它时,我都会收到错误消息。但是这个数组是在头文件中定义的。 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;
}

提前致谢

最佳答案

如果在你的头文件中你有:

@property(nonatomic, strong)NSArray *nFragmentFilterItems;

你必须调用:

self.nFragmentFilterItems = [NSArray arrayWithObjects:@"Min", @"Max", nil];

此外,您还必须在实现文件中综合您的属性:

@synthesize nFragmentFilterItems;

关于iphone - 获取 NSArray 的 EXC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13351877/

相关文章:

iphone - 从其他应用程序请求数据 iphone

objective-c - iOS super 奇怪的问题, subview 没有我添加就添加了

ios - 加载 View Controller 而不显示 Nib

ios - 编辑 CGPath 的 "vertices"?

ios - Xcode 6.3.2 - 无法通过 MapKit 获取位置

objective-c - 处理推送通知

iphone - 以编程方式访问应用标识符前缀

html - iPhone 5S Mobile Safari 超链接不是 'clickable'

iphone - 在 iphone 中以编程方式列出所有 wifi SSID

objective-c - 用于 Objective C 的免费 UML 图工具