滚动 UITableView 时出现 EXC_BAD_ACCESS 错误
我已从 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;
}
I have loaded data of my apps in UITableView from array declared in AppDelegate. But when I try to scroll the table view I am getting EXC_BAD_ACCESS error. Following is the code that I have used for configuring the cell.
- (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;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,似乎在我为委托数组填充对象时,我没有在属性之前使用“self”一词,这导致每次都将指针设置为第一个元素,并最终在我尝试向下滚动它时使我的程序崩溃。非常感谢所有的评论。
Well it seems to be while I was populating objects for delegate array, I did not used 'self' word before property which resulted in setting pointer to 1st element every time and ultimately crashing my program when I tried to scroll it down. Thanks a lot for all comments.