简体   繁体   English

应用突然在我的NSMutableArray的NSLog上崩溃

[英]App suddenly crashes on an NSLog of my NSMutableArray

I have a very strange problem. 我有一个很奇怪的问题。 I've made an app, everything works ok. 我已经制作了一个应用,一切正常。 But now it suddenly crashes on my NSMutableArray . 但是现在它突然崩溃在我的NSMutableArray

Here is a screenshot of the situation 这是情况的屏幕截图

在此处输入图片说明

A few days ago everything worked normal. 几天前,一切正常。 Can it be that this comes because of the update of XCODE and IOS 7 or is it something else? 可能是由于XCODE and IOS 7的更新XCODE and IOS 7还是其他原因? Can somebody help me? 有人可以帮我吗? if you need more detailed information. 如果您需要更详细的信息。 Please ask. 请问。

EDIT The array comes from a mutableCopy of my fetchRequest results. 编辑该数组来自我的fetchRequest结果的mutableCopy。

NSArray *matches = [context executeFetchRequest:fetchRequest error:nil];
newsArray = [matches mutableCopy];

EDIT 2 编辑2

    -(void)fetchNews{
        newsArray = [[NSMutableArray alloc]init];
        RKManagedObjectStore *store = [[TerbremeDataModel sharedDataModel] objectStore];
        NSManagedObjectContext *context = store.mainQueueManagedObjectContext;

        NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"News"];

        NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"new_id" ascending:NO];
        fetchRequest.sortDescriptors = @[descriptor];
        NSArray *matches = [context executeFetchRequest:fetchRequest error:nil];
        newsArray = [matches mutableCopy];
        [tableview reloadData];
    }

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

    NewsCell *cell = (NewsCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if (cell == nil)
    {
        NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"NewsCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"tablecellbg.png"]];
    cell.accessoryView = [[ UIImageView alloc ] initWithImage:[UIImage imageNamed:@"tableArrow.png" ]];
    News *news = [newsArray objectAtIndex:indexPath.row];
    NSLog(@"news is %@",news);
    static NSDateFormatter *df;
    static NSDateFormatter *df2;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        df = [[NSDateFormatter alloc] init];
       [df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];

        df2 = [[NSDateFormatter alloc] init];
        [df2 setDateFormat:@"d MMMM yyyy"];
    });


    cell.lblText.font = [UIFont fontWithName:@"GillSans" size:15.0];
    cell.lblDate.font = [UIFont fontWithName:@"GillSans" size:15.0];

    cell.lblDate.textColor = [UIColor colorWithRed:(154/255.0) green:(202/255.0) blue:(0/255.0) alpha:100];

    cell.lblText.text = news.new_title;
    NSDate *date = [df dateFromString:news.new_datepublished];
   cell.lblDate.text = [df2 stringFromDate:date];

    return cell;
}

If you are using ARC I would assign the newsArray using the objective c facilities, ie the generated accessor method. 如果您使用的是ARC,我将使用目标c工具(即生成的访问器方法)分配newsArray。

So it would be 原来如此

self.newsArray = [[NSMutableArray alloc]init]; self.newsArray = [[NSMutableArray alloc] init];

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

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