2012-11-18 1 views
2

인덱스에있는 오브젝트가 실패하는 이유를 모르겠습니다. 나는 누군가가 이것을 바로 잡는 방법을 알고 있는지 궁금해하고 있었다. 실패한 특정 코드는 무효로드 이미지의 하단에 NSURL *imgURLLogo = [NSURL URLWithString:[[firstMessage objectForKey:@"message"] objectForKey:@"photo"]];입니다. 아무도 알아낼 수 없습니까?SInvalidArgumentException ', 이유 :'- [NSArrayM objectForKey :] :

static NSString *CellIdentifier = @"Cell"; 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
// if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:CellIdentifier] autorelease]; 

    // Configure the cell... 
    NSMutableArray *arrMessages = [objectsForContacts objectForKey:[arrayOfUsers objectAtIndex:indexPath.row]]; 

    NSMutableDictionary *firstMessage = [arrMessages objectAtIndex:0]; 

    UILabel *lblFriendName = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 200, 20)]; 
    lblFriendName.textAlignment = UITextAlignmentLeft; 
    lblFriendName.backgroundColor = [UIColor clearColor]; 
    lblFriendName.textColor = [UIColor blackColor]; 
    lblFriendName.font = [UIFont boldSystemFontOfSize:16.0]; 
    lblFriendName.text = [[firstMessage objectForKey:@"message"] objectForKey:@"toname"]; 
    [cell.contentView addSubview:lblFriendName]; 

    UILabel *lblLastMessage = [[UILabel alloc] initWithFrame:CGRectMake(10, 25, 280, 35)]; 
    lblLastMessage.textAlignment = UITextAlignmentLeft; 
    lblLastMessage.numberOfLines = 2; 
    lblLastMessage.backgroundColor = [UIColor clearColor]; 
    lblLastMessage.textColor = [UIColor blackColor]; 
    lblLastMessage.font = [UIFont systemFontOfSize:13.0]; 
    lblLastMessage.text = [[firstMessage objectForKey:@"message"] objectForKey:@"text"]; 
    [cell.contentView addSubview:lblLastMessage]; 

    UILabel *lblTime = [[UILabel alloc] initWithFrame:CGRectMake(10, 60, 280, 20)]; 
    lblTime.textAlignment = UITextAlignmentLeft; 
    lblTime.backgroundColor = [UIColor clearColor]; 
    lblTime.textColor = [UIColor blackColor]; 
    lblTime.font = [UIFont systemFontOfSize:13.0]; 
    lblTime.text = [NSString stringWithFormat:@"%@",[[[firstMessage objectForKey:@"message"] objectForKey:@"postedat"] substringToIndex:16]]; 
    [cell.contentView addSubview:lblTime]; 

    cell.backgroundColor = appDelegate.pref_TableViewCellColorValue; 
    // cell.textLabel.text = [[dict objectForKey:@"post"] objectForKey:@"title"]; 
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    NSMutableDictionary *dict = [[objectsForCharacters objectForKey:[arrayOfCharacters objectAtIndex:indexPath.section]] objectAtIndex:indexPath.row]; 


    UIImageView *imgUser = [[UIImageView alloc] initWithFrame:CGRectMake(5, 1, 48, 48)]; 
    if (![dict objectForKey:@"cellimage"]) { 
     UIImage *img = [appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[UIImage imageNamed:@"smily.png"]]; 
     imgUser.image = img; 
     NSMutableArray *arrObject = [[NSMutableArray alloc] init]; 
     [arrObject addObject:arrMessages]; 
     [arrObject addObject:imgUser]; 
     [NSThread detachNewThreadSelector:@selector(loadImage:) toTarget:self withObject:arrObject]; 
    } else { 
     UIImage *img = [appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[dict objectForKey:@"cellimage"]]; 
     imgUser.image = img; 
    } 



    [cell.contentView addSubview:imgUser]; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 
    cell.backgroundColor = appDelegate.pref_TableViewCellColorValue; 
    return cell; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    return 80.0; 
} 


- (void)loadImage :(NSMutableArray *)arrObjects { 
    NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; 
    NSMutableDictionary *firstMessage= [arrObjects objectAtIndex:0]; 
    NSURL *imgURLLogo = [NSURL URLWithString:[[firstMessage objectForKey:@"message"] objectForKey:@"photo"]]; 
    NSLog(@"%@",[[firstMessage objectForKey:@"message"] objectForKey:@"photo"]); 
    UIImage *imgLogo = [UIImage imageWithData:[NSData dataWithContentsOfURL:imgURLLogo]]; 
    if (imgLogo) 
     [firstMessage setObject:imgLogo forKey:@"cellimage"]; 
    else 
     [firstMessage setObject:[appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[UIImage imageNamed:@"smily.png"]] forKey:@"cellimage"]; 
    [self performSelectorOnMainThread:@selector(loadingImageComplete:) withObject:arrObjects waitUntilDone:YES]; 
    [pool release]; 
} 

-(void) loadingImageComplete :(NSMutableArray *)arrayOfUsers1 { 
    NSMutableDictionary *dict = [arrayOfUsers1 objectAtIndex:0]; 
    UIImageView*imgUser1 = [arrayOfUsers1 objectAtIndex:1]; 
    UIImage *img = [appDelegate imageByScalingProportionallyToSize:CGSizeMake(48, 48) img:[dict objectForKey:@"cellimage"]]; 
    imgUser1.image = img; 
} 

다음은 무슨 일이 일어나고 있는지에 대한 nslog입니다.

 { 
    message =   { 
     id = 20; 
     name = Road; 
     postedat = "2012-11-17 17:11:51"; 
     status = sent; 
     text = "mickey d"; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 23; 
     name = Road; 
     postedat = "2012-11-17 17:11:40"; 
     status = sent; 
     text = "ok message gone wierd"; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 17; 
     name = Road; 
     postedat = "2012-11-17 17:11:29"; 
     status = sent; 
     text = my; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 19; 
     name = Road; 
     postedat = "2012-11-17 17:11:26"; 
     status = sent; 
     text = moo; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 22; 
     name = Road; 
     postedat = "2012-11-17 17:11:19"; 
     status = sent; 
     text = loops; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 21; 
     name = Road; 
     postedat = "2012-11-17 17:11:09"; 
     status = sent; 
     text = ok; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 18; 
     name = Road; 
     postedat = "2012-11-17 17:11:05"; 
     status = sent; 
     text = moo; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 13; 
     name = Road; 
     postedat = "2012-10-24 13:10:48"; 
     status = sent; 
     text = test; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 16; 
     name = Road; 
     postedat = "2012-10-24 13:10:39"; 
     status = sent; 
     text = hi; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 15; 
     name = Road; 
     postedat = "2012-10-24 13:10:36"; 
     status = sent; 
     text = test; 
     toname = Road; 
     userid = 52; 
    }; 
}, 
    { 
    message =   { 
     id = 14; 
     name = Road; 
     postedat = "2012-10-24 13:10:26"; 
     status = sent; 
     text = yes; 
     toname = Road; 
     userid = 52; 
    }; 
} 

)

+0

지금 가지고있는 많은 코드 대신에 이것을 재현 가능한 샘플로 줄이는 것이 좋습니다. –

+0

NSLog (@ "% @", firstMessage);를 실행하고 결과를 보여줍니다. 그 대답을 지시합니다. 분명히, 사전/배열의 구조는 예상 한 것과 다릅니다. – Rob

+0

좋아, 나는 당신이 물어보고 출력을 게시했다. – moo

답변

1

arrMessages가 마치이있는 NSArray의 배열이다. 따라서 arrMessages의 첫 번째 요소는 NSArray이 아니고 NSDictionary이 아닙니다.

+0

혹시 이걸 고칠 수 있었는지 아십니까? – moo

+0

objectsForContacts가 채워지는 곳을 선택하십시오. 이 코드에는 문제가없는 것 같습니다. – diederikh

0
NSMutableArray *arrMessages = [objectsForContacts objectForKey:[arrayOfUsers objectAtIndex:indexPath.row]]; 

objectsForContacts 란 무엇입니까? 배열 또는 사전입니까? 그것의 배열 인 경우, 그것이 잘못된 것입니다.

관련 문제