-(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];
        }else{
            NSLog(@"notnil");
            NSMutableArray *array = [classVideoDic objectForKey:classId];
            [array addObject:dic];
            [classVideoDic  setObject:array forKey:classId];
        }
    };
    self.dataItems = classVideoArray;
    NSLog(@"cc==%d",[classVideoDic count]);
    NSLog(@"bb==%d",[classVideoArray count]);以上代码是声明并赋值给classVideoDic对象的相关代码,classVideoDic是.h文件里声明的一个属性
知道报的错误表示classVideoDic对象被销毁了,但我没有其他地方掉过他的release方法,并且开始打印出的[classVideoDic count]是有值的,但不知道为什么在给tableview绑定时就成被释放的对象了,求高人指点啊!
其中第二段代码是[request setDidFinishSelector:@selector(getClassFinished:)];所绑定的回调函数getClassFinished里的

解决方案 »

  1.   

    classVideoDic创建得时候用得是autorelease方式,虽然是一个熟悉,如果没有明确得对象所属,缺省为成员变量classVideoDic;一个成员变量用autorelase方式,它得释放跟autoreleasepool 有很大关系,不是很保险,说不定什么时候会释放;解决方法:
    1.classVideoDic 属性声明成retain方式,self.classVideoDic = [NSMutableDictionary dictionaryWithCapacity:5];
    2.创建classVideoDic 之后,调用[classVideoDic retain];当然在delalloc时也不许掉release;否则内存泄露
      

  2.   

    成员变量可以使用alloc方法来初始化,或者说你现在的方法后面加一个retain或者改成属性调用