【问题标题】:-[__NSCFString objectAtIndex:] cellForRowAtIndexPath: crashes when trying to access arrays objectAtIndex:indexPath.row-[__NSCFString objectAtIndex:] cellForRowAtIndexPath: 尝试访问数组时崩溃 objectAtIndex:indexPath.row
【发布时间】:2013-03-05 08:23:02
【问题描述】:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xa84a800'

我正在将数据从自定义 UITableViewCell自己的类和 nib)加载到 UITableView。效果很好,直到我尝试访问某些数组的objectAtIndex:indexPath.row

我会先发布我的代码,这样你可能会更容易理解我的意思。

-(void)viewWillAppear:(BOOL)animated
{
self.navigationController.navigationBarHidden=YES;
if (managedObjectContext==nil) {
    MFAppDelegate *appDelegate = (MFAppDelegate *)[UIApplication sharedApplication].delegate;
    managedObjectContext = appDelegate.managedObjectContext;

}

NSFetchRequest *request = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"Last" inManagedObjectContext:managedObjectContext];
[request setEntity:entity];
NSError *error = nil;
NSMutableArray *mutableFetchResults = [[managedObjectContext executeFetchRequest:request error:&error] mutableCopy];
if (mutableFetchResults == nil) {
    // Handle the error.
}

// Set self's events array to the mutable array, then clean up.
[self setFinal:mutableFetchResults];
lastdisarr=[mutableFetchResults valueForKey:@"lastdis"];
lastcalarr=[mutableFetchResults valueForKey:@"lastcal"];
lasttimearr=[mutableFetchResults valueForKey:@"lasttime"];
date=[mutableFetchResults valueForKey:@"lastspeed"];
lasticonarr=[mutableFetchResults valueForKey:@"iconwe"];
NSLog(@"LAst DISTANCE %@",lasticonarr);

}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:   (NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"cell";
Cell *cell = [table dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil)
{
    [[NSBundle mainBundle]loadNibNamed:@"Cell" owner:self options:nil];

    cell=self.custom;
}

// Set up the cell...

cell.distance.text=[lastdisarr objectAtIndex:indexPath.row];
cell.timelab.text=[lasttimearr objectAtIndex:indexPath.row];
cell.callab.text=[lastcalarr objectAtIndex:indexPath.row];
cell.date.text=[date objectAtIndex:indexPath.row];
//cell.wether.image=[lasticonarr objectAtIndex:indexPath.row];


NSMutableArray *ar=[lasticonarr objectAtIndex:indexPath.row];
NSLog(@"%@",ar);

//问题来了

//我想在自定义单元格中显示图像并从核心数据中获取路径....路径正在获取但图像未显示在单元格上

NSURL *url1 = [NSURL URLWithString:[ar objectAtIndex:indexPath.row]];

NSLog(@"%@",url1);
NSData *data = [NSData dataWithContentsOfFile:[ar description]];


NSLog(@"%@",data);

return cell;

}

【问题讨论】:

    标签: uitableview ios6 xcode4.5


    【解决方案1】:

    有两种选择:

    1:你没有保留你的价值;

    lastdisarr  = [[mutableFetchResults valueForKey:@"lastdis"] retain];
    lastcalarr  = [[mutableFetchResults valueForKey:@"lastcal"] retain];
    lasttimearr = [[mutableFetchResults valueForKey:@"lasttime"] retain];
    

    2:[mutableFetchResults valueForKey:@"lastdis"]NSString,而不是 NSArray,正如预期的那样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-05
      • 1970-01-01
      • 2018-02-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多