简体   繁体   English

释放线程1 exc_bad_access

[英]releasing thread1 exc_bad_access

I am new at IOS programing and I have program that works fine, but I found out that it has memory leek, so I start releasing object. 我是IOS编程的新手,我的程序可以正常运行,但是我发现它具有内存韭葱,因此我开始释放对象。

When I now start the program it give me an error: 当我现在启动程序时,它给我一个错误:

@autoreleasepool {
     return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
} 

and : 和:

Thread 1: EXC_BAD_ACCESS (code = 1, address = 0x3f800010)

I tried to debug it and I found out that program crashed at creating tableView. 我尝试对其进行调试,发现该程序在创建tableView时崩溃。 It create whole first section, but in the second row in second section it crashed in the returning line. 它创建了整个第一节,但是在第二节的第二行中,它在返回行中崩溃了。

here is my code of creating table: 这是我创建表的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{



[tableView setBackgroundView:nil];
tableView.backgroundColor = [UIColor clearColor];





    // Configure the cell...

    if ([self tableView:tableView canCollapseSection:indexPath.section])
    {
        if (!indexPath.row)
        {
            static NSString *CellIdentifier = @"TitleCell";
            UILabel *title;

            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell = nil;
            if (cell == nil) {
                [[NSBundle mainBundle] loadNibNamed:@"TitleCell" owner:self options:nil];
                titleCell.layer.masksToBounds = YES;
                titleCell.layer.cornerRadius =0.0;
                cell = titleCell;
                self.titleCell = nil;


            }

            title =(UILabel *)[cell viewWithTag:1];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            NSString *orderString=[[[NSString alloc] init] autorelease];





                    title.text = [[titles objectAtIndex:indexPath.section] objectAtIndex:2];
                    cell.accessoryView = nil;



            if (!isPad()) {
                [cell.contentView setBackgroundColor:[UIColor colorWithRed:0.0 green:0.18 blue:0.24 alpha:1]];
            }

            return cell;
        }
        else
        {
            // all other rows

            static NSString *CellIdentifier = @"DataCell";
            UILabel *title;
            UILabel *update;
            UILabel *download;
            UILabel *updateText;
            UILabel *downloadText;

            UIImageView *favoriteIcon;




            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell = nil;
            if (cell == nil) {
                [[NSBundle mainBundle] loadNibNamed:@"DataCell" owner:self options:nil];
                cell = dataCell;
                self.dataCell = nil;


            }


            cell.layer.cornerRadius =0;
            title =(UILabel *)[cell viewWithTag:1];
            download = (UILabel *)[cell viewWithTag:3];
            update = (UILabel *)[cell viewWithTag:2];
            favoriteIcon = (UIImageView *)[cell viewWithTag:4];
            updateText = (UILabel *)[cell viewWithTag:5];
            downloadText = (UILabel *)[cell viewWithTag:6];

            updateText.text = NSLocalizedString(@"updated", nil);
            downloadText.text = NSLocalizedString(@"downloaded", nil);

            NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
            [dateFormat setDateFormat:@"MM. d. YYYY"];
            starIcone = favoriteIcon;
            int indicator = 0;


                    for (int i=0; i<[allData count]; i++) {
                        if ([[[allData objectAtIndex:i] objectAtIndex:1] isEqualToNumber:[[titles objectAtIndex:indexPath.section] objectAtIndex:0]] ) {
                            indicator++;
                        }
                        if (indicator == indexPath.row) {



                            title.text = [[allData objectAtIndex:i] objectAtIndex:2];
                            download.text = [dateFormat stringFromDate:[self db_get_date:[[[allData objectAtIndex:i] objectAtIndex:0]intValue]]];
                            update.text = [dateFormat stringFromDate:[[allData objectAtIndex:i] objectAtIndex:3]];





                            break;
                        }
                    }






            [dateFormat release];

            [favoriteIcon setAccessibilityHint:title.text];
            if ([favorits count]==0) {
                favoriteIcon.image = [[UIImage alloc] 
                                      initWithContentsOfFile:
                                      [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
                                       @"blankstar.png"]];

            }
            for (int i=0; i<[favorits count]; i++) {
                if ([title.text isEqualToString:[[favorits objectAtIndex:i] objectAtIndex:2]]) {
                    favoriteIcon.image = [[UIImage alloc] 
                                          initWithContentsOfFile:
                                          [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
                                           @"star.png"]];
                    break;
                }
                else {
                    favoriteIcon.image = [[UIImage alloc] 
                                          initWithContentsOfFile:
                                          [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:
                                           @"blankstar.png"]];
                }
            }



            UITapGestureRecognizer *recognizer = [[[UITapGestureRecognizer alloc] 
                                                   initWithTarget:self action:@selector(AddIcone:)]autorelease
                                                  ];

            [favoriteIcon setUserInteractionEnabled:YES];
            [favoriteIcon addGestureRecognizer:recognizer];

            cell.backgroundColor = [UIColor clearColor];
            cell.selectionStyle = UITableViewCellSelectionStyleBlue;
            return cell;


        }
    }



return nil;

I also tried just putting : 我也试着把:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"TitleCell";
            UILabel *title;

            UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
            cell = nil;
            if (cell == nil) {
                self.titleCell = [[[NSBundle mainBundle] loadNibNamed:@"TitleCell" owner:self options:nil]objectAtIndex:0];
                titleCell.layer.masksToBounds = YES;
                titleCell.layer.cornerRadius =0.0;
                cell = titleCell;
                self.titleCell = nil;


            }
return cell;

and it crash as before. 和以前一样崩溃。

pleas help me out and thank for your help. 请帮助我,感谢您的帮助。

[[NSBundle mainBundle] loadNibName: owner: options:] returns an array. [[NSBundle mainBundle] loadNibName: owner: options:]返回一个数组。 Replace this line with: 将此行替换为:

self.titleCell = [[[NSBundle mainBundle] loadNibNamed:@"TitleCell" owner:self options:nil] objectAtIndex:0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM