gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 04:15:43 25 4
gpt4 key购买 nike

由于某种原因,加载此 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com