开发者

UITableView didSelectRowAtIndexPath error - when selecting item again

Loaded a list of items on to the UITableview and was able to click and show an alert for the row selected . But however after saying "ok" on the alert and i reclick on the already selected row my code 开发者_JAVA百科breaks down saying "Thread 1:Program received signal:EXC_BAD_ACCESS".please take a look at the code below.

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSDictionary *playerselected = [exercises objectAtIndex:indexPath.row];
    NSString *video = [playerselected valueForKey:@"video"];

    NSString *msg = [[NSString alloc] initWithFormat:@"You have selected %@", video];
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Player selected" 
                                                    message:msg 
                                                   delegate:self 
                                          cancelButtonTitle:@"OK" 
                                          otherButtonTitles:nil];    

    [alert show];     
    [alert release];
    [video release];
    [msg release]; 

}

PLease suggest me what could be the issue here.


Don't release video.

When you retrieve a value from an NSDictionary you don't own it unless you explicitly retain it.

To be more specific, when you retrieve your string it is still owned by the dictionary. When you release it, you are releasing an object that you do not own, resulting in it being over-released. As a result it is deallocated, and when you next try to access it the memory is no longer valid and your app crashes.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜