开发者

UITableView didSelectRowAtIndexPath error - when selecting item again

开发者 https://www.devze.com 2023-04-01 05:58 出处:网络
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 co

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

精彩评论

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