开发者

Getting EXC_BAD_ACCESS error while scrolling UITableView

开发者 https://www.devze.com 2023-03-14 06:47 出处:网络
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 c

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号