【问题标题】:App suddenly crashes on an NSLog of my NSMutableArray应用程序突然在我的 NSMutableArray 的 NSLog 上崩溃
【发布时间】:2013-09-29 11:42:42
【问题描述】:

我有一个很奇怪的问题。我做了一个应用程序,一切正常。 但现在它突然在我的NSMutableArray 上崩溃了。

这里是情况截图

几天前一切正常。会不会是因为XCODE and IOS 7的更新,还是别的什么原因? 有人可以帮助我吗?如果您需要更详细的信息。请问一下。

编辑 该数组来自我的 fetchRequest 结果的 mutableCopy。

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

编辑 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;
}

【问题讨论】:

  • 分配了新数组
  • 控制台的崩溃日志是什么?它会打印出任何崩溃的原因吗?
  • 同时将您的id sender 转换为NSIndexPath 可能是个坏主意...在这种情况下您的sender 是什么?
  • 添加更多信息.. 问题不太清楚。
  • 显示 newsArray 的分配情况

标签: iphone ios objective-c core-data nsmutablearray


【解决方案1】:

如果您使用 ARC,我将使用目标 c 工具(即生成的访问器方法)分配 newsArray。

原来如此

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 1970-01-01
    • 2019-11-03
    • 2012-06-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多