解决方案 »

  1.   

    好吧,虽然木有人鸟俺,不过俺还是自己解决了发上来供需要的人参考吧。
    static NSString *cellId = @"CYZBookShelfViewCell";
        CYZBookCell *cell = (CYZBookCell *)[tableView dequeueReusableCellWithIdentifier:cellId];
        
        if (cell == nil) {
            cell = [[CYZBookCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
        }
        
        cell.booksGroup = [self.bookGroup2D objectAtIndex:indexPath.row];
        
        return cell;
    在cell协议方法中,用deque方法取cell,如果为nil则将调用initWithStyle:reuseIdentifier:方法初始化cell。而自定义的cell正是将初始化方法加在了这里面。我所谓的初始化,是指将子视图item加到cell.contentView中并为之设tag值。而当deque方法不再返回nil的时候,此时便不再调用initWithStyle:reuseIdentifier:方法了,奇怪的是,这个时候对重用的cell,用[cell.contentView viewWithTag:] 方法取不到item视图了。之前运行地挺好,ios8之后就不行了。不过ios在取cell前会调用prepareForReuse方法。所以既然cell上有重复视图,并且cell没有初始化(添加子视图),那就在这个方法中处理即可。注意不要忘了super一下。
    - (void)prepareForReuse
    {
        [super prepareForReuse];    [self removeAllSubviews];
        [self p_initView];
    }