当前位置: 代码迷 >> Iphone >> 应用uitable的cellForRowAtIndexPath方法里数据对象总被莫名其妙的释放~求高人指点
  详细解决方案

应用uitable的cellForRowAtIndexPath方法里数据对象总被莫名其妙的释放~求高人指点

热度:78   发布时间:2016-04-25 06:02:59.0
使用uitable的cellForRowAtIndexPath方法里数据对象总被莫名其妙的释放~求高人指点
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *myIdentifier=@"OnlineCell";
    static BOOL nibsRegistered = NO;
    if (!nibsRegistered) {
        UINib *nib = [UINib nibWithNibName:@"OnlineCell" bundle:nil];
        [tableView registerNib:nib forCellReuseIdentifier:myIdentifier];
        nibsRegistered = YES;
    }
     NSLog(@"*********3");
    OnlineCell *cell = [tableView dequeueReusableCellWithIdentifier:myIdentifier];
    NSUInteger row=[indexPath row];
    NSMutableDictionary *classDic = [CLASSNAMES objectAtIndex:[indexPath section]];
    NSString *classid = [classDic objectForKey:@"id"];
    NSLog(@"classid:%@",classid);
     
    if([classVideoDic count]>0 && classid!=nil){
        NSLog(@"*********??");
        NSMutableArray *array = [classVideoDic objectForKey:classid];
        NSMutableDictionary *dic =[array objectAtIndex:row];
        NSLog(@"*********4");
        NSString *cellName =  [dic objectForKey:@"videoname"];
        NSString *pic =  [dic objectForKey:@"videopicurl"];
        NSLog(@"*********5");
        //    NSLog(@"%@",cellName);
        [cell.onlineLabel setText:cellName];
        NSData* imageData = [[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:pic]];
        UIImage *image = [[UIImage alloc]initWithData:imageData];
        [cell.imageView setImage:image];
    }
   
    return cell;
}

以上是方法里绑定数据的代码,报的错误是[__NSDictionaryM count]: message sent to deallocated instance 
classVideoDic = [NSMutableDictionary dictionaryWithCapacity:5];
    for (int i=0; i<[classVideoArray count]; i++) {
        NSMutableDictionary *dic =[classVideoArray objectAtIndex:i];
        NSString *classId =  [dic objectForKey:@"videoclassid"];
        if([classVideoDic objectForKey:classId]==nil){
            NSLog(@"isnil");
            NSMutableArray *array = [NSMutableArray arrayWithObjects:dic, nil];
            [classVideoDic  setObject:array forKey:classId];