- [__ NSCFString objectAtIndex:] cellForRowAtIndexPath:尝试访问数组时崩溃objectAtIndex:indexPath.row

时间:2013-03-05 08:23:02

标签: uitableview ios6 xcode4.5

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFString objectAtIndex:]: unrecognized selector sent to instance 0xa84a800'

我从自定义UITableView自己的类和笔尖)将数据加载到UITableViewCell。它工作得很好,直到我尝试访问某些数组的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;

}

1 个答案:

答案 0 :(得分:0)

有两种选择:

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

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

2:[mutableFetchResults valueForKey:@"lastdis"]NSString,而不是预期的NSArray