【问题标题】:UITableView didSelectRowAtIndexPath error - when selecting item againUITableView didSelectRowAtIndexPath 错误 - 再次选择项目时
【发布时间】:2011-11-08 21:45:15
【问题描述】:

将项目列表加载到 UITableview 上,并且能够单击并显示所选行的警报。但是,在警报上说“确定”之后,我重新单击已选择的行,我的代码会分解为“线程 1:程序收到信号:EXC_BAD_ACCESS”。请看下面的代码。

- (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]; 

}

请告诉我这里可能存在什么问题。

【问题讨论】:

  • 好的,我看了一下。你有什么特别想提的问题吗?开个玩笑,尽管如果您提出特定问题确实会有所帮助,并提供尽可能多的细节以帮助我们解决您的问题(例如,错误发生在哪一行)。只是在没有解释的情况下转储代码并不能很好地激励其他人提供帮助。
  • Sry MAc ..更正了上面的问题。

标签: uitableview xcode4 uialertview didselectrowatindexpath


【解决方案1】:

不要释放video

当您从 NSDictionary 检索值时,除非您明确地 retain 它,否则您并不拥有它。

更具体地说,当您检索字符串时,它仍归字典所有。当您release 它时,您正在释放一个您不拥有的对象,从而导致它被过度释放。结果,它被释放,当您下次尝试访问它时,内存不再有效,您的应用程序崩溃。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-23
    • 2014-06-10
    • 2021-06-14
    • 2011-11-19
    • 1970-01-01
    • 1970-01-01
    • 2011-08-06
    相关资源
    最近更新 更多