繁体   English   中英

滚动时iOS UITableView崩溃

[英]iOS UITableView crashes when scrolling

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

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

  • 向下滚动到最后一个元素时为EXC_BAD_ACCESS
  • 当我滚动到第一个之上时, SIGABRT具有回溯

我在Google上浏览时,似乎释放了太多对象,但是我不知道是哪个对象。

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

这里是一些相关的代码:

    /*
     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加载和卸载方法:

- (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中添加对象(如新控制器)时,默认情况下会自动释放该对象。

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

根据经验,边界滚动和边界滚动之间的最大区别在于,边界滚动经过表的所有元素(包括页眉和页脚),并且很可能会重新计算行数。 如果您有页眉和页脚,请尝试在其中放置断点。

关于EXC_BAD_ACCESS,可以在malloc_error_break中放置一个断点,以期希望更多地了解谁未正确释放。 这是一个符号断点,可通过“断点”窗口上的“ +”按钮进行定义。

暂无
暂无

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

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