在表中滚动时,“EXC_BAD_ACCESS”、“-[CFString release]:发送到已释放实例的消息”

2024-05-24

滚动时出现以下错误UITableview. EXC_BAD_ACCESS, -[CFString keep]:发送到已释放实例的消息

我怎样才能找到已解除分配的实例...? 这是我的 noOfRowsinsection 代码

for(int i=0;i<size;i++)
{
    NSString *CellIdentifier1;
    if(universalApp==2)
    {
        NSAutoreleasePool *pool=[[NSAutoreleasePool alloc]init];
    CellIdentifier1 = @"CustomThumbImageTableCell_iphone";
    cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];

        //NSLog(@">>>>> Creating image >>>>>>>>");
    //cell.thumbImageView = [[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)];
    cell.thumbImageView = [[[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)] autorelease];

    [imgViewArray addObject:cell.thumbImageView];

    [cell.thumbImageView release];  
        [pool release];

    }

这是我的 cellforRow 代码

enter code hereif(universalApp==2)
{
    NSLog(@"iphone cell>>>>>>>>>>>>>>>>>>>>>>");

    CustomThumbImageTableCell *cell = nil;


    @try
    {
        static NSString *CellIdentifier = @"CustomThumbImageTableCell_iphone";
        int currentRow = [indexPath row] ;//+ skippedItems;
        //NSLog(@">>>>>>>>>>>>Current Table row = %d, %d, %d", loadedCellArray.count, currentRow, [Table numberOfRowsInSection:0]);


        /*if(loadedCellArray.count > currentRow + 1 && [loadedCellArray objectAtIndex:(currentRow)] != nil)
         {
         NSLog(@"Image updated = %d", ( currentRow));

         cell = (CustomThumbImageTableCell_iphone *) [loadedCellArray objectAtIndex:(currentRow )];

         }
         else
         {*/

        /*if(loadedCellArray.count > currentRow + 1 )// && [loadedCellArray objectAtIndex:(currentRow)] != nil)
         // if( [loadedCellArray objectAtIndex:(currentRow)] != nil)
         {
         //NSLog(@"Image updated = %d", ( currentRow));

         cell = (CustomThumbImageTableCell_iphone *) [loadedCellArray objectAtIndex:([indexPath row]  )];
         if(!isScrollingUp) 
         {
         //scrollCount++;
         [loadedCellArray removeLastObject];
         }
         isScrollingUp = YES;

         }
         else*/
        {

            static NSString *CellIdentifier = @"CustomThumbImageTableCell_iphone";
            static NSString *CellIdentifier1 = @"CustomThumbImageTableCell_iphone";
            //UITableViewCell *cell;

            if(cell==nil)
            {
                cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
            }
            else
            {
                cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier1];
                cell = [[[CustomThumbImageTableCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier1] autorelease];

            }
            cell.selectionStyle = UITableViewCellSelectionStyleNone;

            NSLog(@">>>>>>>>>..... %d, %d, %@", imgViewArray.count, indexPath.row, (((int)imgViewArray.count- 1) < (int)indexPath.row) ? @"YES" : @"NO");
            /*if(((int)imgViewArray.count- 1) < (int)indexPath.row)
            {
                //  NSLog(@">>>>> Creating image >>>>>>>>");
                cell.thumbImageView = [[CustomImageView alloc] initWithFrame:CGRectMake(4, 4, 83, 101)];

                [imgViewArray addObject:cell.thumbImageView];
            }
            else {
                cell.thumbImageView = (CustomImageView *) [imgViewArray objectAtIndex:indexPath.row];
            }*/
            //NSLog(@"img array = %@,%d",imgViewArray,imgViewArray.count);

            cell.thumbImageView =[imgViewArray objectAtIndex:indexPath.row];
            cell.thumbImageView.contentMode = UIViewContentModeScaleAspectFit;
            [cell.contentView addSubview:cell.thumbImageView];

            cell.thumbImageView.index = (int)indexPath.row;

            @try
            {

                {
                    BOOL isFound = NO;
                    do
                    {   
                        @try {
                            NSArray *array1 = [contentString componentsSeparatedByString:@"@@#"];
                            NSArray *array2 = [[array1 objectAtIndex:currentRow ] componentsSeparatedByString:@"##"];           
                            NSString *str = [NSString stringWithFormat:@"%@", [array2 objectAtIndex:0]];
                            str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

                            UILabel *name = [[UILabel alloc] initWithFrame:CGRectMake(104, 6, 141, 96)];
                            name.textAlignment = UITextAlignmentCenter;
                            name.font = [UIFont fontWithName:@"Arial" size:17.0];
                            name.numberOfLines = 3;
                            name.backgroundColor = [UIColor clearColor];
                            name.textColor = [UIColor whiteColor];
                            cell.catalogName = name;
                            [cell.catalogName setText:[NSString stringWithFormat:@"%@", str]];
                            [cell.contentView addSubview:cell.catalogName];
                            //[name release];

                            name = [[UILabel alloc] initWithFrame:CGRectMake(107, 89, 193, 21)];//107,89,193
                            name.textAlignment = UITextAlignmentCenter;
                            name.font = [UIFont fontWithName:@"Arial" size:13.0];
                            name.textColor = [UIColor whiteColor];
                            name.numberOfLines = 3;
                            name.backgroundColor = [UIColor clearColor];
                            name.alpha = 0.26;
                                cell.pageNo = name;

                                [cell.contentView addSubview:cell.pageNo];
                            //[name release];



                            if((searchId != 2 && (isLineNameSearchEnabled == 0)) || searchInCatalogFlag == 1)
                                //cell  Page No//pageNoLabel
                                //NSLog(@"cell for row.......");
                                [cell.pageNo setText:[NSString stringWithFormat:@"Page No: %@", [array2 objectAtIndex:(array2.count - 2)]]];


                            {

                            }

                            NSLog(@" thumb image = %@",[NSString stringWithFormat:@"%@%@", baseURL,  [array2 objectAtIndex:1]]);

                            //[cell.thumbImageView setImageURL:@"http://www.zoomcatalog.com/sites/default/files/catalogs/27705_Abex2010/images/thumbnails/Thumb-1.jpg"];
                            [cell.thumbImageView setImageURL:[NSString stringWithFormat:@"%@%@", baseURL,  [array2 objectAtIndex:1]]];
                            [NSThread detachNewThreadSelector:@selector(initThread) toTarget:cell.thumbImageView withObject:nil];
                            [cell.thumbImageView setPageNo:((searchId == 2 || (isLineNameSearchEnabled && searchInCatalogFlag == 0)) ? 0 : (int)currentRow)];


                            UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(264, 33, 36, 34)];
                            img.contentMode = UIViewContentModeScaleToFill;
                            [img setImage:cellArrow];
                            [cell.contentView addSubview:img];

                            [img release];

                            [cell.catalogName release];
                            //>>>>      [cell.pageNoLabel release];
                            [cell.thumbImageView release]; 
                            isFound = YES;
                        }
                        @catch (NSException * e) {
                            //skippedItems++;
                            currentRow = [indexPath row] + 1;
                        }

                    }
                    while (!isFound);




                    /*if(isScrollingUp)
                     {
                     //scrollCount++;
                     [loadedCellArray removeLastObject];
                     }
                     isScrollingUp = NO;
                     currentRow =indexPath.row;     
                     // cell = (CustomThumbImageTableCell_iphone *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
                     if (cell == nil)
                     {
                     //cell = (CustomThumbImageTableCell_iphone *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

                     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomThumbImageTableCell_iphone" owner:self options:nil];
                     //cell = (CustomThumbImageTableCell_iphone *) [loadedCellArray objectAtIndex:(currentRow )];
                     cell = self.cell;
                     self.cell = nil;

                     }  
                     NSLog(@"Image loaded from source= %d,", ( currentRow));
                     //if(loadedCellArray.count > currentRow + 1)
                     // NSLog(@"Image loaded from source cell array ref= %@", [loadedCellArray objectAtIndex:(currentRow)]);

                     /*if(currentRow == ([Table numberOfRowsInSection:0] - 1))
                     {
                     cell.catalogName.text = @"50 More";
                     NSLog(@">>>>>>>>>>>>>>>>>>>>> End cell....");
                     return cell;
                     }
                     /////
                     // if(true)
                     // return cell;
                     @try
                     {

                     {
                     BOOL isFound = NO;
                     do
                     {  
                     @try {
                     NSArray *array1 = [contentString componentsSeparatedByString:@"@@#"];
                     NSArray *array2 = [[array1 objectAtIndex:currentRow] componentsSeparatedByString:@"##"];           
                     NSString *str = [NSString stringWithFormat:@"%@", [array2 objectAtIndex:0]];
                     str = [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
                     // NSLog(@"&&&&&&&&&&&&&&&&& %@", str);
                     [cell.catalogName setText:[NSString stringWithFormat:@"%@", str]];
                     if((searchId != 2 && (isLineNameSearchEnabled == 0)) || searchInCatalogFlag == 1)
                     [cell.pageNo setText:[NSString stringWithFormat:@"Page No: %@", [array2 objectAtIndex:(array2.count - 2)]]];

                     // NSLog(@"Background color has been set....%d", i);
                     //NSLog(@")
                     //NSLog(@"Catalog %d = %@", currentRow, [array1 objectAtIndex:currentRow]);
                     // NSLog(@"Image URL = %@", [NSString stringWithFormat:@"%@%@", baseURL,  [array2 objectAtIndex:1]]);

                     [cell.thumbImageView setImageURL:[NSString stringWithFormat:@"%@%@", baseURL,  [array2 objectAtIndex:1]]];
                     //[cell.thumbImageView setContentString:contentString];
                     //if(searchId == 2)
                     // [cell.thumbImageView setContentString:[NSString stringWithFormat:@"%@", [array2 objectAtIndex:(array2.count - (isLineNameSearch ? 2 :  2))]]];

                     [cell.thumbImageView performSelectorOnMainThread:@selector(initThread) withObject:nil waitUntilDone:NO];
                     [cell.thumbImageView setPageNo:(searchId == 2 ? @"0" : [indexPath row])];

                     isFound = YES;
                     }
                     @catch (NSException * e) {
                     //skippedItems++;
                     currentRow = [indexPath row] + 1;
                     }
                     */ 
                    //  }
                    //  while(!isFound);// && currentRow < [Table numberOfRowsInSection:0]);

                    //[imgViewArray addObject:cell.thumbImageView];



                    //  [imgViewArray retain];



                    //[label setTextColor:[UIColor blackColor]];
                    //[label setTextAlignment:UITextAlignmentCenter];
                    /*          UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(7 + ((i % 3) * (96 + 8)) , 9 + ((i / 3) * (140 + 10)), 98, 142)];
                     [label setBackgroundColor:[UIColor grayColor]];
                     [scrollView addSubview:label];

                     [imgViewArray addObject:imgView];
                     [scrollView addSubview:imgView];
                     if(i % 3 == 0)
                     {
                     [scrollView setContentSize:CGSizeMake(scrollView.contentSize.width, scrollView.contentSize.height + (140 + 10))];
                     }*/
                }
                //[imgViewArray retain];
                //  [cellArray retain];
            }

当您遇到内存管理问题时,您可以执行以下操作:

  1. 重读可可内存管理规则 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/MemoryMgmt/Articles/mmRules.html并确保您正在关注他们。
  2. Run the 静态分析仪 http://developer.apple.com/library/mac/#featuredarticles/StaticAnalysis/。这通常会发现您忽略内存管理规则的地方。
  3. 由于看起来您已经启用了 NSZombies,因此插入一个断点[_NSZombie release]。这应该会打破导致问题的线路。

Edit:

根据您的代码,以下行可能是罪魁祸首。

[cell.thumbImageView release]; // NOT GOOD

同样,在您的其他代码中您有:

[cell.thumbImageView release]; // NOT GOOD
[cell.catalogName release]; // NOT GOOD

您将自动释放的对象设置为thumbImageView and catalogName细胞的属性,但你仍在尝试释放它。这不是 Cocoa 内存管理的工作原理。你不own cell.thumbImageView or cell.catalogName,所以你不应该释放它们。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在表中滚动时,“EXC_BAD_ACCESS”、“-[CFString release]:发送到已释放实例的消息” 的相关文章

  • 将 iPad xib 转换为 iPhone xib

    我看过很多关于将 iPhone xib 转换为 iPad xib 的帖子和教程 但我想反过来做 我能找到的唯一资源是 将 iPad 应用程序转换为 iPhone https stackoverflow com questions 68550
  • iPhone 上的语音识别

    我需要开发一个识别语音的 iPhone 应用程序 并根据结果执行进一步的任务 我知道iPhone 3 0不支持语音识别 我需要在服务器端实现语音识别软件 我只知道这个事情 因为我是新手 所以我不知道如何处理 意味着我需要购买哪些软件并在服务
  • iphone sqlite 静态链接?

    有人静态链接 sqlite 而不是使用动态链接 吗 我遇到的问题是 越狱手机的用户没有与普通 iPhone 所采用的 sqlite 版本相同的版本 因此导致崩溃 我假设在我的应用程序中静态链接已知版本的 sqlite 就是答案 我需要全文支
  • 如何在iOS中查找文本段范围

    如何在 iOS 中找到文本段 又名代码段 范围 意思是 文本段的起始地址和结束地址是多少 I found 这个有趣的帖子 http www pschweitzer fr p 12但它适用于 Android 但不适用于 iOS 经过一些挖掘和
  • 在后台轮询服务器的正确方法

    假设这是可能的 我希望我的 iOS 应用程序在后台时轮询服务器 即基本上每 30 分钟检索一次 URL 的内容 并通知用户是否包含 有趣 的内容 基本上以类似的方式如果您不使用推送通知 则内置邮件客户端假定的工作方式 现在 从我到目前为止的
  • 如何获取原始触摸屏数据?

    我知道我可以在 iPhone 应用程序中获取触摸事件 但这些触摸事件都被我过滤掉了 如果我将设备按在脸上 它会过滤掉这些触摸事件 因为它可以检测到它不是手指 我如何获得原始触摸事件 而不以任何方式过滤 没有用于此目的的公共 API 您可以获
  • 如何在 iPhone 应用程序中使用正则表达式以 , (逗号)分隔字符串

    我必须读取包含三列的 csv 文件 在解析 csv 文件时 我得到了这种格式的字符串克里斯托弗 巴斯 为心爱的国家哭泣 期末论文 电子邮件受保护 cdn cgi l email protection 我想将三列的值存储在一个数组中 所以我使
  • 特定时间的 iPhone 本地通知

    我想每周晚上 10 点 无论哪个国家 地区 发出通知 我需要使用时区吗 目前 我使用下面的代码每周触发通知 但如何在晚上 10 点准确触发通知 NSDate date NSDate date NSDate myNewDate date da
  • 在完成块中保留循环

    在我的课堂上 我创建了这个方法 void refreshDatasourceWithSuccess CreateDataSourceSuccessBlock successBlock failure CreateDataSourceFail
  • rightBarButtonItem 信息按钮,右侧没有空格

    我有一个UIViewController设置为在其右侧显示一个信息按钮UINavigationItem像这样 UIButton infoButton UIButton buttonWithType UIButtonTypeInfoLight
  • 如何使用 iOS 可达性

    我正在开发一个使用网络的 iPhone 应用程序 iPhone 通过 HTTP 请求与我的服务器通信 并且应该可以在 WiFi 和 3G 上运行 我目前使用NSURLConnection initWithRequest向我的服务器发送异步请
  • 如何在 UITableView 中显示零行的表格

    我正在动态地将内容加载到 UITableView 中 如果有数据 表格需要显示数据 如果没有数据 表格应显示普通页面 但在我的应用程序中 表格显示带有两条分隔线的普通页面 我需要删除此分隔线并显示纯白色页面 请建议 任何帮助 将不胜感激 如
  • 如何在iOS中处理1到3个手指的滑动手势

    我使用以下代码来处理代码中的 1 根手指滑动 UISwipeGestureRecognizer swipe UISwipeGestureRecognizer alloc initWithTarget self action selector
  • 如何以编程方式更改 iPhone APN(接入点名称)?

    如何以编程方式更改 iPhone APN 接入点名称 或者强制 3G GPRS 连接以编程方式使用特定的 APN 无法通过 SDK 完成 第三方应用程序无法对硬件进行这种级别的控制 尤其是蜂窝调制解调器
  • iPhone 上的双精度与浮动

    我刚刚听说 iPhone 本身无法进行双倍操作 从而使它们比常规浮动慢得多 这是真的 证据 我对这个问题很感兴趣 因为我的程序需要高精度计算 而且我将不得不在速度上妥协 iPhone 可以在硬件中执行单精度和双精度算术 在 1176 原始
  • 在 iPhone 3GS 与 iPhone 4 上为 Mobile Safari 嵌入 HTML5 视频

    我在服务器上的 mp4 文件中有 H 264 AAC 编码的视频 mime 类型的视频 mp4 添加到 Web 服务器 IIS 7 并且我有一个带有视频标签的页面
  • UIView animateWithDuration:delay: 工作很奇怪

    我在使用 iPhone 动画块时遇到了一个奇怪的问题 这段代码 UIView animateWithDuration 2 delay 0 options 0 animations void controller setBackgroundC
  • iPhone:UIApplication WillResignActiveNotification 从未被调用

    我正在视图控制器中播放视频 当用户按下硬件主页按钮并且当前正在播放视频时 应用程序崩溃并显示EXC BAD ACCESS在模拟器中 我读到我应该使用applicationWillResignActive停止视频播放的消息应该可以解决崩溃问题
  • 如果我使用自定义 UITableViewCell,是否需要设置 heightForRowAtIndexPath?

    如果我使用自定义 UITableViewCell 是否需要设置 heightForRowAtIndexPath 在我的 NIB 中 我已经设置了单元高度 当我覆盖 heightForRowAtIndexPath 时 单元格的内容不会出现 即
  • 是否可以跨 2 个不同的 iOS 应用程序访问数据?

    假设我在 App1 中存储了一些 ID 数据 并希望在同一设备上的 App2 中访问它 平台上可以这样吗 如果没有的话有什么解决方法吗 您可以使用iOS 钥匙扣 http developer apple com library ios do

随机推荐