gpt4 book ai didi

ios - UITableView cellForRowAtIndexPath 中的 EXEC_BAD_ACCESS

转载 作者:可可西里 更新时间:2023-11-01 04:21:48 25 4
gpt4 key购买 nike

我的 UITableView 正在返回 EXEC_BAD_ACCESS,但为什么!

请看这段代码!

加载 UITableView 工作正常,所以 allXYZArray != nil 并被填充!

然后将 tableview 滚动到底部并返回会导致它崩溃,因为它会重新加载方法 cellForRowAtIndexPath

在线失败:

    "NSLog(@"allXYZArray::count: %i", [allXYZArray count]);"

(UITableViewCell *)tableView:(UITableView *)theTableView cellForRowAt

IndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"CellIdentifier";
UITableViewCell *cell = [theTableView dequeueReusableCellWithIdentifier:CellIdentifier];


cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
@try
{
if (allXYZArray == nil) {
NSLog(@"nil");
allXYZArray = [ToolBox getMergedSortedDictionaries:allXYZGiven SecondDictionary:allXYZSought];
}
NSLog(@"%i", [indexPath row]);
NSLog(@"allXYZArray::count: %i", [allXYZArray count]);

最佳答案

EXC_BAD_ACCESS 表示您的程序正在尝试访问一个无效的内存地址或您的进程无法访问的内存地址。当您尝试向已被释放的对象发送消息时,最常发生这种情况。因此,调试 EXC_BAD_ACCESS 的第一步是找出崩溃发生时您的程序试图向哪个对象发送消息。通常答案并不明显,在这种情况下,NSZombieEnabled是识别哪一行代码导致崩溃的好工具。

在您的情况下,您已经确定当您调用 [allXYZArray count] 时会发生崩溃,从而使 allXYZArray 成为我们的主要嫌疑人。此对象是从 +[ToolBox getMergedSortedDictionaries:SecondDictionary:] 返回的,因此您的错误很可能出在该方法的实现中。我猜它会返回一个已经被释放的对象,而不是自动释放的,正如 Memory Management Programming Guide for Cocoa 所规定的那样。 . (顺便说一下,这是 SDK 中最重要的文档之一。我建议每月重读一次,直到它的策略和技术成为第二天性。)

关于ios - UITableView cellForRowAtIndexPath 中的 EXEC_BAD_ACCESS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2734413/

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