来自调试器的Ios Xcode消息:由于内存问题而终止 [英] Ios Xcode Message from debugger: Terminated due to memory issue

查看:272
本文介绍了来自调试器的Ios Xcode消息:由于内存问题而终止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有收藏夹视图的应用程序,该收藏夹视图中的单元格重定向到外部链接.

I have an app with collection view and a cell within this collection view that redirects to external link.

只要该链接打开,应用程序就会在后台崩溃并在调试器上显示:

Whenever that link opens the app crashs in the background and gives on the debugger:

由于内存问题而终止".

"Terminated due to memory issue".

如果我只按主页按钮,则该应用程序将继续正常运行.

If I just press home button the app continues working just fine.

if (UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)) Portrait = NO;
else if (UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation)) Portrait = YES;
else Portrait = [self getStatusBarOrientations];

if(indexPath.row == 4 && indexPath.section == 0)
{
    NewsListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"Cell4"  forIndexPath:indexPath];

    if ([languageID isEqualToString:@"1025"])
    {
        cell.title.text =[NSString stringWithFormat:@"جريدة اليوم %@", [self.pdfCoverDict valueForKey:@"PdfDate"]];
        [cell.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];
    } else {
        cell.title.text =[NSString stringWithFormat:@"Today's Edition %@", [self.pdfCoverDict valueForKey:@"PdfDate"]];
    }
    NSURL *imageUrl = [NSURL URLWithString:[self.pdfCoverDict valueForKey:@"CoverImage"]];
    [cell.imageView sd_setImageWithURL:imageUrl];
    cell.imageViewWidth.constant = Portrait ? 246 : 331;
    cell.imageViewHeight.constant = Portrait ? 350 : 471;
    return cell;

} else if(indexPath.row == 0) {
    NewsListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"HeaderView" forIndexPath:indexPath];
    cell.title.text = [self.channelKeys objectAtIndex:indexPath.section];
    cell.backView.hidden = [channelID isEqualToString:@"1"] ? (indexPath.section == 0 ? YES : NO) : YES;
    if([languageID isEqualToString:@"1025"]) {
        [cell.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];
    } else {
        [cell.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];
        [cell.title setTransform:CGAffineTransformMakeScale(-1, 1)];
    }
    return cell;
} else {

    NSInteger row;
    if(indexPath.row != 1 && indexPath.row != 2 && indexPath.row != 3) {
        row = indexPath.row - 2;
    } else {
        row = indexPath.row - 1;
    }
    NSMutableArray * articles =  [self.channelArticles valueForKey:[self.channelKeys objectAtIndex:indexPath.section]];
     //        if(row < articles.count) {
    NSString *articleImage = [[articles objectAtIndex:row] valueForKey:@"ArticleMedia"];
    NSString *cellIdentifier;
    NSString *articleLangID = [NSString stringWithFormat:@"%@", [[articles objectAtIndex:row] valueForKey:@"LanguageID"]];

    if(indexPath.section == 0) {
        switch (indexPath.row)
        {
            case 1:
                if(![articleImage isEqualToString:@""]) cellIdentifier = @"Cell1";
                else cellIdentifier = @"CellNoImg";
                break;
            case 2:
                if(![articleImage isEqualToString:@""]) cellIdentifier = @"Cell2";
                else cellIdentifier = @"CellNoImg";
                break;
            case 3:
                if(![articleImage isEqualToString:@""]) cellIdentifier = @"Cell3";
                else cellIdentifier = @"CellNoImg";
                break;
            case 5:
                if(![articleImage isEqualToString:@""]) cellIdentifier = @"Cell5";
                else cellIdentifier = @"CellNoImg";
                break;
            case 6:
                if(![articleImage isEqualToString:@""]) cellIdentifier = @"Cell5";
                else cellIdentifier = @"CellNoImg";
                break;
            default:
                if(![articleImage isEqualToString:@""]) {
                    if([channelID isEqualToString:@"1"]) cellIdentifier = @"Cell6";
                    else cellIdentifier = @"Cell5";
                } else {
                    cellIdentifier = @"CellNoImg";
                }
                break;
        }
    } else {
        if(![articleImage isEqualToString:@""]) cellIdentifier = @"Cell5";
        else cellIdentifier = @"CellNoImg";
    }


    NewsListCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:cellIdentifier forIndexPath:indexPath];

    if([[[articles objectAtIndex:row] valueForKey:@"LabelName"] isEqualToString:@""]) {
        cell.labelNameHeight.constant = 0;
    } else {
        cell.labelNameHeight.constant = 21;
    }
    cell.labelName.text = [[articles objectAtIndex:row] valueForKey:@"LabelName"];

    cell.title.text = [[articles objectAtIndex:row] valueForKey:@"MainHeadline"];

    if(indexPath.row == 3 && indexPath.section == 0) {
        if(![articleImage isEqualToString:@""]) cell.titleHeight.constant = [self lineCountForLabel:cell.title labelWidth:cell.frame.size.width - Portrait ? 254 : 337] * 35;
        else cell.titleHeight.constant = [self lineCountForLabel:cell.title labelWidth:cell.frame.size.width - 10] * 35;
    } else {
        cell.titleHeight.constant = [self lineCountForLabel:cell.title labelWidth:cell.frame.size.width - 10] * 35;
    }

    NSString *authorTime = [self getAuthorTime:[articles objectAtIndex:row]];
    if([authorTime isEqualToString:@""]) {
        cell.authorTimeHeight.constant = 0;
    } else {
        cell.authorTimeHeight.constant = 21;
    }
    cell.authorTime.text = authorTime;

    NSString *details = [[articles objectAtIndex:row] valueForKey:@"Introduction"];
    cell.details.attributedText = [self getAttributedString: details language: articleLangID];

    if([cellIdentifier isEqualToString:@"CellNoImg"]) {
        defaultLines = 5;
        if([cell.authorTime.text isEqualToString:@""]) defaultLines++;
        if([cell.labelName.text isEqualToString:@""]) defaultLines++;
        if(cell.titleHeight.constant / 35 == 1) defaultLines++;
        cell.details.numberOfLines = defaultLines;
    }

    if(indexPath.section == 0) {
        switch (indexPath.row)
        {
            case 2:
                cell.imageViewWidth.constant = Portrait ? 240 : 323;
                cell.imageViewHeight.constant = Portrait ? 151 : 199;
                break;
            case 3:
                cell.imageViewWidth.constant = Portrait ? 240 : 323;
                cell.imageViewHeight.constant = Portrait ? 151 : 199;
            case 5:
                cell.imageViewWidth.constant = Portrait ? 240 : 323;
                cell.imageViewHeight.constant = Portrait ? 151 : 199;
                break;
            case 6:
                cell.imageViewWidth.constant = Portrait ? 240 : 323;
                cell.imageViewHeight.constant = Portrait ? 151 : 199;
                break;
            default:
                cell.imageViewWidth.constant = Portrait ? 240 : 323;
                cell.imageViewHeight.constant = Portrait ? 151 : 199;
                break;
        }
    } else {
        cell.imageViewWidth.constant = Portrait ? 240 : 323;
        cell.imageViewHeight.constant = Portrait ? 151 : 199;
    }

    if (![articleImage isEqualToString:@""]) {
        NSURL *imageUrl = [NSURL URLWithString:articleImage];
        [cell.imageView sd_setImageWithURL:imageUrl];

    } else {
        [cell.imageView sd_setImageWithURL:nil];
    }

    if([articleLangID isEqualToString:@"1025"]) {
        [cell.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];
        cell.labelName.textAlignment = NSTextAlignmentRight;
        cell.title.textAlignment = NSTextAlignmentRight;
        cell.authorTime.textAlignment = NSTextAlignmentRight;
        cell.details.textAlignment = NSTextAlignmentRight;
    } else {
        if (indexPath.row == 3) {
            [cell.contentView setTransform:CGAffineTransformMakeScale(-1, 1)];
            [cell.labelName setTransform:CGAffineTransformMakeScale(-1, 1)];
            [cell.title setTransform:CGAffineTransformMakeScale(-1, 1)];
            [cell.authorTime setTransform:CGAffineTransformMakeScale(-1, 1)];
            [cell.details setTransform:CGAffineTransformMakeScale(-1, 1)];
            [cell.imageView setTransform:CGAffineTransformMakeScale(-1, 1)];
        }
        cell.labelName.textAlignment = NSTextAlignmentLeft;
        cell.title.textAlignment = NSTextAlignmentLeft;
        cell.authorTime.textAlignment = NSTextAlignmentLeft;
        cell.details.textAlignment = NSTextAlignmentLeft;
    }
    return cell;

}

}

推荐答案

这是在什么设备上发生的?一旦您的应用程序进入后台,您就可以随时将其杀死-不必使用过多的内存.

What device is this happening on? Once your app is in the background you can expect for it to be killed at any time - it doesn't have to be using excessive memory.

如果新的前台应用程序需要更多的内存,则操作系统将为其分配尽可能多的内存.它将向任何后台应用发送内存警告.如果他们没有通过减少内存占用量做出响应,或者前台应用程序仍然需要更多内存,那么后台应用程序将被杀死.

If the new foreground app wants more memory, the OS will give it as much as it can. It will send a memory warning to any backgrounded apps. If they don't respond by reducing the memory footprint, or the foreground app still wants more memory, then the background apps are killed.

您的应用程序没有崩溃,正在被操作系统杀死,因为它不再是前台应用程序,并且在其他地方需要它的资源.

Your app isn't crashing, it is being killed by the OS because it is no longer the foreground app and its resources are needed elsewhere.

这篇关于来自调试器的Ios Xcode消息:由于内存问题而终止的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆