【问题标题】:Getting EXC_BAD_ACCESS error while scrolling UITableView滚动 UITableView 时出现 EXC_BAD_ACCESS 错误
【发布时间】:2011-06-21 18:17:58
【问题描述】:

我已经从 AppDelegate 中声明的数组中加载了 UITableView 中我的应用程序的数据。但是当我尝试滚动表格视图时,我收到了 EXC_BAD_ACCESS 错误。以下是我用于配置单元格的代码。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    ScoutAppDelegate *appDelegate = (ScoutAppDelegate *)[[UIApplication     sharedApplication] delegate];
    return appDelegate.playerList.count;

}

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

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

    ScoutAppDelegate *appDelegate = (ScoutAppDelegate *)[[UIApplication sharedApplication] delegate];
    Player *tempPlayer = (Player *)[appDelegate.playerList objectAtIndex:indexPath.row];

    cell.textLabel.text= tempPlayer.playerName;
    return cell;
}

【问题讨论】:

  • 日志中没有太多内容 2011-06-21 15:49:33.519 Scout[5799:207] 文件存在:/Users/ryanfannin/Library/Application Support/iPhone Simulator/4.3.2/Applications/ C78E05BD-8E2B-48E0-8C33-BD8FAEE76905/文档 2011-06-21 15:49:33.522 Scout[5799:207] 启动数据库 2011-06-21 15:49:33.969 Scout[5799:207] 记录数:833
  • 应用程序崩溃后,键入 backtrace 并在控制台窗口中按 Enter。这应该会在崩溃时为您提供堆栈跟踪。此外,如果您使用的是 Xcode 4,我喜欢使用设置异常断点,它在某些情况下会有所帮助。 dosomethinghere.com/2011/04/18/xcode-4-exception-breakpoint
  • 尝试使用 NSZombieEnabled。也许你会得到崩溃的功能。 ;-)
  • 我的第一个猜测是您的 playerList 没有正确保留。

标签: ios uitableview delegates exc-bad-access uiapplicationdelegate


【解决方案1】:

似乎是在我为委托数组填充对象时,我没有在属性之前使用“self”字样,这导致每次都将指针设置为第一个元素,并在我尝试向下滚动时最终导致程序崩溃。非常感谢所有cmets。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-25
    • 2014-05-31
    • 2018-11-20
    • 1970-01-01
    • 2016-01-19
    相关资源
    最近更新 更多