简体   繁体   English

iPhone应用程序在iOS 4.3中因EXC_BAD_ACCESS错误而崩溃,但在以前的版本上可以正常运行

[英]Iphone app crashes with EXC_BAD_ACCESS error in iOS 4.3 but works fine on previous versions

I have created an app which is approved by apple and currently buyable in the appstore. 我创建了一个应用程序,该应用程序已获得苹果的认可,目前可在应用商店中购买。 But after the 4.3 update it crashes when scrolling the UITableView with the EXC_BAD_ACCESS error. 但是,在4.3更新之后,滚动带有EXC_BAD_ACCESS错误的UITableView时,它会崩溃。 NSZombieEnabled = YES, will get the app working again but this isn't a solution of course ;) The error is reported in the Main class on the following line: NSZombieEnabled = YES,将使应用程序再次运行,但这当然不是解决方案;)在主类的以下行中报告了该错误:

int retVal = UIApplicationMain(argc, argv, nil, nil);

Also the stacktrace doesn't help me out either: 另外,堆栈跟踪也不能帮助我:

> #0  0x00faf09f in objc_msgSend ()
> #1  0x04c7b9e0 in ?? ()
> #2  0x00d6004c in CFRelease ()
> #3  0x00e42369 in -[__NSArrayM removeObjectAtIndex:] ()
> #4  0x00e3dcfc in -[NSMutableArray removeObjectsInRange:] ()
> #5  0x003507a5 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] ()
> #6  0x0034890c in -[UITableView layoutSubviews] ()
> #7  0x01d80a5a in -[CALayer layoutSublayers] ()
> #8  0x01d82ddc in CALayerLayoutIfNeeded ()
> #9  0x01d280b4 in CA::Context::commit_transaction ()
> #10 0x01d29294 in CA::Transaction::commit ()
> #11 0x01d2946d in CA::Transaction::observer_callback ()
> #12 0x00e2a89b in __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__
> ()
> #13 0x00dbf6e7 in __CFRunLoopDoObservers ()
> #14 0x00d87857 in CFRunLoopRunSpecific ()
> #15 0x00d87761 in CFRunLoopRunInMode ()
> #16 0x017371c4 in GSEventRunModal ()
> #17 0x01737289 in GSEventRun ()
> #18 0x002dec93 in UIApplicationMain ()
> #19 0x000026d4 in main (argc=1, argv=0xbffff068) at
> /Users/geoffrey/Documents/iPhone
> projecten/Xcode Projecten/HU
> Rooster/main.m:14

Can someone please help me out with this? 有人可以帮我这个忙吗? I'm trying to get this working for 2 days now :( 我现在想让它工作2天:(

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *CellIdentifier = @"Cell";

    CustomCell *cell = (CustomCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
        cell = customCell;
        self.customCell = nil;
    }
    int num = indexPath.row;

    if (indexPath.section != 0) {
        for (int i=1; i <= indexPath.section; i++) {
            num = (num + [[sectorSize objectAtIndex:(i-1)] intValue]);
        }
    }
    // Configure the cell...
        cell.tijdLabel.text = [NSString stringWithFormat:@"%@ - %@", [tijdBeginList objectAtIndex:num], [tijdEindList objectAtIndex:num]];
        cell.lesVormLabel.text = [lesVormList objectAtIndex:num];
        cell.docentLabel.text = [docentList objectAtIndex:num];
        cell.lokaalLabel.text = [lokaalList objectAtIndex:num];
        cell.opmerkingLabel.text = [opmerkingList objectAtIndex:num];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

Check the dealloc method of your Custom Cell implementation and make sure [super dealloc] is the last instruction. 检查自定义单元实现的dealloc方法,并确保[super dealloc]是最后一条指令。 I had a similar issue and it turned out I had it calling [super dealloc] before it was releasing some view labels and other items. 我有一个类似的问题,结果是我在释放一些视图标签和其他项目之前调用了[super dealloc]。

These lines 这些线

> #3  0x00e42369 in -[__NSArrayM removeObjectAtIndex:] ()
> #4  0x00e3dcfc in -[NSMutableArray removeObjectsInRange:] ()
> #5  0x003507a5 in -[UITableView(_UITableViewPrivate) _updateVisibleCellsNow:] (

Give me a hunch that the problem is in the cells you are creating at cellForRowAtIndexPath selector. 让我预感到问题出在在cellForRowAtIndexPath选择器上创建的单元格中。 Something might end up being over released. 某些东西可能最终被过度释放。

Something is being over released and from the look of the stack trace it seems to be a UITableViewCell that is being released one too many times. 有些东西已经被过度释放,并且从堆栈跟踪的外观来看,似乎是一个UITableViewCell被释放了太多次。

You say that NSZombieEnabled = YES keeps it running, which actually surprises me. 您说NSZombieEnabled = YES使它保持运行,这实际上使我感到惊讶。 What NSZombie does, at least when I've been using it, is that it tells you what deallocated object was sent what message, but the application still crashes. NSZombie所做的(至少在我使用的时候)是它告诉您已释放的对象已发送了什么消息,但是应用程序仍然崩溃。

To further help you it would be helpful if you could provide the output from NSZombie as well as your implementation of: 为了进一步帮助您,如果您可以提供NSZombie的输出以及以下实现的话,将会很有帮助:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

EDIT: I've never used the interface builder, but I found a line that I found suspicious: 编辑:我从未使用过界面生成器,但是我发现了可疑的一行:

self.customCell = nil;

If the customCell property is a retain property, that line will release the custom cell. 如果customCell属性是retain财产,该行会发布的自定义单元格。 Try changing that property to an assign property. 尝试将该属性更改为assign属性。

The difference might be that 不同之处可能是

[[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];

used to retain the custom cell in previous versions, but doesn't in 4.3. 用于保留以前版本中的自定义单元,但不包含在4.3中。 You should figure it out, so that you're not leaking in older versions. 您应该弄清楚,以免泄漏旧版本。 Drop a comment if you need more help. 如果您需要更多帮助,请发表评论。

EDIT 2: Ok, so I have one more idea. 编辑2:好的,所以我还有一个主意。

You could check the retain count of the cell: 您可以检查单元格的保留计数:

NSLog(@"Retain count: %i", [cell retainCount]);

You could check the retain count in different places and compare it between 4.3 and prior versions. 您可以在不同位置检查保留计数,并将其与4.3和以前的版本进行比较。 Maybe that way you could figure out what have changed. 也许那样您可以找出发生了什么变化。

I also read the documentation for loadNibNamed:owner:options: and found the following that might be relevant: 我还阅读了有关loadNibNamed:owner:options:的文档,发现以下内容可能相关:

(To establish outlet connections, this method uses the setValue:forKey: method, which may cause the object in the outlet to be retained automatically.) (要建立插座连接,此方法使用setValue:forKey:方法,这可能会导致插座中的对象自动保留。)

The documentation says that the object may be retained, so I guess that's a behavior that might change between versions. 文档说该对象可能会保留,所以我猜这是一个行为,可能会在版本之间发生变化。

Your mistake is that you are assigning the cell pointer to the customCell pointer, then setting the customCell to nil, meaning cell will be pointing to a non-valid object. 您的错误是您将cell指针分配给customCell指针,然后将customCell设置为nil,这意味着cell将指向无效对象。

Use cell = [[customCell copy] autorelease]; Use cell = [[customCell copy] autorelease]; instead and you should be good to go. 相反,您应该很好。

First, you are reading the stack trace backwards. 首先,您正在向后读取堆栈跟踪。 The crash is in [__NSArrayM removeObjectAtIndex:] (or just below). 崩溃位于[__NSArrayM removeObjectAtIndex:] (或在下面)。

Secondly, the problem indicates an object was created, put into an array, and then released to the point of deallocation while the array still held onto it. 其次,问题表明创建了一个对象,将其放入数组中,然后释放到释放位置,同时数组仍保留在该对象上。 This is an all too common over-release problem. 这是一个太常见的过发行问题。

Here: 这里:

    [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
    cell = customCell;
    self.customCell = nil;

You grab a reference to the customCell and then promptly release it. 您获取对customCell的引用,然后立即释放它。 The only reason why it likely sticks around is because NIB loading probably retained/autoreleased the object on load. 它可能停留的唯一原因是因为NIB加载可能会在加载时保留/自动释放对象。

Rog's suggestion of retain/autoreleasing the cell is a good one. 罗格建议保留/自动释放单元格是一个很好的建议。

But there is a bigger problem; 但是,还有一个更大的问题。 you are loading a nib in the middle of trying to draw a table view . 您在尝试绘制表格视图时正在装入笔尖

Loading a NIB is a relatively glacially slow operation to be doing in the middle of something as performance sensitive as drawing a table. 加载NIB是一项相对缓慢的操作,它在像绘制表格一样对性能敏感的过程中进行。 It is quite likely that your app's scrolling and/or user interaction is going to be "clunky" because of this. 因此,您的应用程序的滚动和/或用户交互很有可能会变得“笨拙”。

While cell = [[customCell retain] autorelease]; cell = [[customCell retain] autorelease]; might fix the crash, I would suggest that you also refactor the code to not do something so expensive during table rendering. 可能会解决崩溃问题,我建议您也重构代码,以免在表呈现期间执行如此昂贵的操作。

I was getting same issue ... 我遇到了同样的问题...

in cellForRowAtIndexPath:(NSIndexPath *)indexPath 在cellForRowAtIndexPath中:(NSIndexPath *)indexPath

Check your CellIdentifier with CellIdentifier of xib file ... 使用xib文件的CellIdentifier检查您的CellIdentifier ...

make your CellIdentifier = @"CustomCell" 使您的CellIdentifier = @“ CustomCell”

This will fix your issue 这将解决您的问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM