Reputation: 131
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 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.
Upvotes: 1
Views: 533
Reputation: 14791
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.
Upvotes: 2