滚动时iOS UITableView崩溃 [英] iOS UITableView crashes when scrolling

查看:108
本文介绍了滚动时iOS UITableView崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里遇到了一个奇怪的问题.我正在开发一个iOS应用程序(专门针对iPad),并且在某些时候使用UITableView来显示事物列表.

I ran into a bizarre issue here. I'm developping an iOS app (for iPad, specifically), and I'm using an UITableView at some point to display a list of things.

现在,当我在视图范围内滚动时(不在第一个元素上方,也不在最后一个元素下方),它可以正常工作.但是,当我进一步滚动时,它只会崩溃,没有其他消息:

Now, when I scroll inside the bounds of the view (not above first element, and not below the last), it works okay. However, it just crashes violently when I scroll further than that, with no other messages than :

    向下滚动到最后一个元素时,
  • EXC_BAD_ACCESS
  • SIGABRT ,当我滚动到第一个上方时回溯
  • EXC_BAD_ACCESS when I scroll down to the last element
  • SIGABRT with a backtrace when I scroll upper than the first

我查看了Google,看来我释放了太多对象,但我不知道是哪个对象.

I looked on Google, and it seems like I'm releasing some objects too much, but I can't figure out which ones.

我也尝试过在Instruments内运行该应用程序,但是每次运行该应用程序时,Instruments窗口都会冻结,迫使我用手杀死它……当然我没有任何结果...

I also tried running the app inside the Instruments, but the Instruments window just freezes each time I run the app, forcing me to kill it by hand... And of course I get no results...

下面是一些相关代码:

    /*
     Returns the cells of the table view
     */
    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        // Create a new cell view
        static NSString *CellIdentifier = @"Cell";

        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
        if (cell == nil) {
            cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        }

        // Configure the cell...
        cell.textLabel.text = [newestModules objectAtIndex:indexPath.row];
        cell.textLabel.textColor = [UIColor whiteColor];
        cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"Background-Texture-Dark-Small.png"]];
        cell.imageView.image = [UIImage imageNamed:@"Icon-Maths.png"];

        UIView *v = [[[UIView alloc] initWithFrame:cell.frame] autorelease];

        // Set view background color
        v.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Background-Texture-Dark-Small.png"]];

        // This view will be activated when the cell is selected
        cell.selectedBackgroundView = v;

        return cell;
    }

UITableView的加载和卸载方法:

UITableView Load and Unload methods :

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Transparent background
    self.tableView.backgroundView = nil;

    // Generate list of newest modules. Will later look for them on the internet, but for now we only add some test examples.
    newestModules = [[NSMutableArray alloc] initWithObjects:@"Test 1", @"Test 2", @"Test 3", @"Test 4", @"Test 5", nil];
}

- (void)viewDidUnload
{
    [newestModules release];
    [super viewDidUnload];
}

推荐答案

似乎,当您在Interface Builder中添加对象(如新控制器)时,它会由自动释放默认.

It seems that, when you add an object, like a new controller, inside the Interface Builder, it is auto-released by default.

如果不将其与类中的 retained 属性链接,则在初始化后立即释放它,从而导致可怕的 EXC_BAD_ACCESS 错误.

If you don't link it with a retained property inside a class, it gets released right after its initialization, causing the dreaded EXC_BAD_ACCESS error.

这篇关于滚动时iOS UITableView崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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