【发布时间】: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