Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/121.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Objective c 应用程序因错误而崩溃:修改正在定稿的层_Objective C_Ios_Subview - Fatal编程技术网

Objective c 应用程序因错误而崩溃:修改正在定稿的层

Objective c 应用程序因错误而崩溃:修改正在定稿的层,objective-c,ios,subview,Objective C,Ios,Subview,我的应用程序在滚动浏览tableview后出现消息“正在修改正在定稿的图层”,正在崩溃 我相信这个错误是由于我在方法的末尾发布了“videoView”(最后一行代码) 我如何解决这个问题 - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString* PlaceholderCellIdentifier = @"

我的应用程序在滚动浏览tableview后出现消息“正在修改正在定稿的图层”,正在崩溃

我相信这个错误是由于我在方法的末尾发布了“videoView”(最后一行代码)

我如何解决这个问题

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString* PlaceholderCellIdentifier = @"PlaceholderCell";

    GenericObject *youTubeVid = [self.searchResultArray objectAtIndex:indexPath.row];

    UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:PlaceholderCellIdentifier];
    if (cell == nil)
    {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier]autorelease];

    }
    UIWebView *videoView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 104, 104)];

    NSString *cellid=[NSString stringWithFormat:@"Cell%i%i", indexPath.section, indexPath.row];

    if([self.webViewCache objectForKey:cellid])
    {
        videoView=[self.webViewCache objectForKey:cellid];
    }
    else
    {
        NSString *url = [NSString stringWithFormat:@"http://www.youtube.com/watch?v=%@",youTubeVid.vid];
        NSString *videoHTML = [self embedYouTube:url frame:CGRectMake(0, 0, 104, 104)];
        [videoView loadHTMLString:videoHTML baseURL:nil];
        [self.webViewCache setObject:videoView forKey:cellid]; //Save webview in dictionary
    }

    [cell.contentView addSubview:videoView];

    //Error seems to be here
    [videoView release];

    return cell;
}

这个错误是因为这条线

if([self.webViewCache objectForKey:cellid])
{
    videoView=[self.webViewCache objectForKey:cellid];
}
这里您只是从一个字典中获取web视图,它显然返回一个
自动删除的
对象。因此,当您试图释放它时(不知道它是已分配的还是刚从字典中获取的),就会发生错误

一种解决方案是
保留
视频视图

videoView=[[self.webViewCache objectForKey:cellid] retain];

这个错误是因为这条线

if([self.webViewCache objectForKey:cellid])
{
    videoView=[self.webViewCache objectForKey:cellid];
}
这里您只是从一个字典中获取web视图,它显然返回一个
自动删除的
对象。因此,当您试图释放它时(不知道它是已分配的还是刚从字典中获取的),就会发生错误

一种解决方案是
保留
视频视图

videoView=[[self.webViewCache objectForKey:cellid] retain];
  • 你正在分配

    UIWebView *videoView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 104, 104)];
    
  • 然后,您可以将此引用替换为其他引用

    videoView=[self.webViewCache objectForKey:cellid];
    
  • 那么当你

    [videoView release];
    
  • 你永远不知道你是在释放在第1点还是第2点获得的记忆。如果是#2,您可能会在后续调用中过度释放

    EmptyStack解决方案可以解决您的问题。在实施时,还要注意释放您在第1点中所做的分配

  • 你正在分配

    UIWebView *videoView = [[UIWebView alloc]initWithFrame:CGRectMake(0, 0, 104, 104)];
    
  • 然后,您可以将此引用替换为其他引用

    videoView=[self.webViewCache objectForKey:cellid];
    
  • 那么当你

    [videoView release];
    
  • 你永远不知道你是在释放在第1点还是第2点获得的记忆。如果是#2,您可能会在后续调用中过度释放

    EmptyStack解决方案可以解决您的问题。在实施时,还要注意释放您在第1点中所做的分配