Getting EXC_BAD_ACCESS error while scrolling UITableView
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] in开发者_高级运维itWithStyle: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;
}
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.
精彩评论