objective-c - 填充 iOS TableView-EXC BAD_ACCESS 代码 = 1 错误

标签 objective-c ios tableview exc-bad-access

由于某种原因,加载此 View 时我收到上述错误。相同的代码适用于在我之前的 View 中填充 tableView 行,因此我不知道这会出现什么问题 - 这是完全相同的代码。当我转换到此 View 时,应用程序崩溃了。它在正确崩溃之前成功地 NSLog self.tableRows 中的类别,因此 tableRows 中的存储似乎不是问题。它在计算行数的行上崩溃(返回 self.tableRows.count)。我感觉这个错误与无法访问 tableRows 有关,但我对 iOS 很陌生。感谢您的帮助!这是我即将到期的大学类(class)项目,因此我们将不胜感激。

#import "DivisionsViewController.h"
#import "TeamsViewController.h"

@implementation DivisionsViewController

@synthesize tableRows = _tableRows;
@synthesize currentKey = _currentKey;

NSMutableArray* temp;

#pragma mark - Table view data source

- (void)viewDidLoad
{
    [super viewDidLoad];

    _currentKey = @"default";

    //temporary- trying to populate TableView from JSON

    int i = -1;
    self.tableRows = [NSMutableArray array];
    temp = [[NSMutableArray alloc] init];
    for(NSDictionary *dict in self.divisions){
        NSString *category = [dict objectForKey:@"category"];
        if (self.currentKey != category){
            [self.tableRows addObject:category];
            [temp addObject:[[NSMutableArray alloc] init]];
            self.currentKey = category;
            NSLog(@"table value %@", [self.tableRows lastObject]);
            i++;
        }
        [[temp objectAtIndex:i] addObject:dict];
    }
    for (NSString* category in self.tableRows){
        NSLog(@"category: %@", category);
    }
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{

    return self.tableRows.count;        

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DivisionCell" forIndexPath:indexPath];
    cell.textLabel.text = [self.tableRows objectAtIndex:indexPath.row];
    return cell;
}

最佳答案

您是否尝试过 NSLog 您的表行数? 尝试在返回 numberOfRows 之前对其进行 NSlog。

self.tableRows.count

您还可以尝试设置异常断点。 在 xcode 中选择“断点导航器” - 它是选项卡右侧的第二个选项卡。 (您可以在最左侧的选项卡中查看您的项目) 当您位于该选项卡中时,您可以按左下角的 + -> 添加异常断点。然后它在崩溃之前就中断了 - 可能很有用!

关于objective-c - 填充 iOS TableView-EXC BAD_ACCESS 代码 = 1 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13758348/

相关文章:

objective-c - 为什么不调用 UIPinchGestureRecognizer 而 scrollViewDidEndZooming 是?

android - Stella SDK 转安卓

java - 如何将按钮添加到一列 TableView 中的单行?

ios - uitableview 分隔符显示为三角形

objective-c - 无法在 NSDictionary 中获取值

ios - iOS xibs 的动画约束

ios - 通过 AVMutableVideoComposition 和 CAAnimation 输出的黑色视频

ios - 在 Swift 3.0 中类型转换

javafx - 如何正确地将新数据添加到 TableView 并滚动到它

objective-c - UITableView dataSource 必须从 tableView :cellForRowAtIndexPath error 返回一个单元格