UITableView中的EXEC_BAD_ACCESS单元格为ForRowAtIndexPath [英] EXEC_BAD_ACCESS in UITableView cellForRowAtIndexPath

查看:57
本文介绍了UITableView中的EXEC_BAD_ACCESS单元格为ForRowAtIndexPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

My UITableView is returning EXEC_BAD_ACCESS, but why!

请参阅此代码段!

加载UITableView可以正常工作,因此allXYZArray != nil并已填充!

Loading the UITableView works fine, so allXYZArray != nil and is populated!

然后将tableview滚动到底部并进行备份使其崩溃,因为它将重新加载方法cellForRowAtIndexPath

Then scrolling the tableview to the bottom and back up causes it to crash, as it goes to reload the method 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 是识别哪个问题的好工具这行代码导致了崩溃.

EXC_BAD_ACCESS means that your program is trying to access a memory address that is invalid or otherwise inaccessible from your process. This most commonly happens when you try send a message to an object that has already been dealloced. So the first step in debugging EXC_BAD_ACCESS is to figure out which object your program was trying to send a message to when the crash happened. Often the answer isn't obvious, in which case, NSZombieEnabled is a great tool for identifying which line of code caused the crash.

对于您而言,您已经确定在致电[allXYZArray count]时发生崩溃,这使allXYZArray成为我们的主要嫌疑人.该对象是从+[ToolBox getMergedSortedDictionaries:SecondDictionary:]返回的,因此您的错误很可能在该方法的实现中.我猜想它会返回一个已经释放的对象,而不是按照

In your case you've already determined that the crash happens when you call [allXYZArray count], making allXYZArray our prime suspect. This object is being returned from +[ToolBox getMergedSortedDictionaries:SecondDictionary:], so it's likely that your bug is in the implementation of that method. I would guess that it's returning an object that has already been released instead of autoreleased, as prescribed by the Memory Management Programming Guide for Cocoa. (This is one of the most important documents in the SDK, by the way. I recommend rereading it once a month until its policies and techniques become second nature.)

这篇关于UITableView中的EXEC_BAD_ACCESS单元格为ForRowAtIndexPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆