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

我加载数据到UITableView,从自定义UITableViewCell自己的阶级和笔尖):试图访问数组objectAtIndex时崩溃。它工作的很好,直到我试图访问某些数组的objectAtIndex:indexPath.row- [__ NSCFString objectAtIndex:]的cellForRowAtIndexPath: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); 

//问题是在这里

//我要显示的图像中自定义单元格从核心数据....路径& GET路径越来越但图像细胞

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

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


NSLog(@"%@",data); 

return cell; 

} 

回答

0

有两个选项:

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

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

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

相关问题