iOS 融云修改RCConversationListViewController消息列表Cell復(fù)用重疊問題

隨便做個(gè)筆記

- (void)willDisplayConversationTableCell:(RCConversationBaseCell *)cell atIndexPath:(NSIndexPath *)indexPath {
    
    RCConversationCell *baseCell = (RCConversationCell *)cell;
    RCConversationModel *model = self.conversationListDataSource[indexPath.row];
    RCMessage *ms = (RCMessage *)model.lastestMessage;
    
    if (ms.extra != nil) {
        
        NSData *jsonData = [ms.extra dataUsingEncoding:NSUTF8StringEncoding];
        NSError *err;
        NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&err];
        
        if ([dictionary[@"fromContactid"] integerValue] != 0) {

            //cell復(fù)用問題
            for (UIView *view in baseCell.contentView.subviews) {
                if ([view isKindOfClass:UIImageView.class] && view.tag == 120) {
                    [view removeFromSuperview];
                }
                if ([view isKindOfClass:UILabel.class] && view.tag == 110) {
                    [view removeFromSuperview];
                }
            }
            
            UIImageView *view = [[UIImageView alloc] init];
            view.tag = 120;
            [baseCell.contentView addSubview:view];
            view.translatesAutoresizingMaskIntoConstraints = NO;
            NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:baseCell.conversationTitle, @"view1", view,@"view", nil];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[view1]-15-[view(==30)]" options:0 metrics:nil views:dic]];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[view(==20)]" options:0 metrics:nil   views:NSDictionaryOfVariableBindings(view)]];
            
            UILabel *showLabel = [[UILabel alloc] init];
            showLabel.backgroundColor = [UIColor clearColor];
            showLabel.font = [UIFont systemFontOfSize:12];
            showLabel.tag = 110;
            [baseCell.contentView addSubview:showLabel];
            showLabel.translatesAutoresizingMaskIntoConstraints = NO;
            NSDictionary *showLabelDic = [NSDictionary dictionaryWithObjectsAndKeys:view, @"view1", showLabel,@"view",baseCell.messageCreatedTimeLabel,@"view2", nil];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[view1]-0-[view]-0-[view2]" options:0 metrics:nil views:showLabelDic]];
            [baseCell addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[showLabel(==20)]" options:0 metrics:nil   views:NSDictionaryOfVariableBindings(showLabel)]];
        
            if ([dictionary[@"fromContactid"] integerValue] == 1) {
                
                showLabel.text = @"她想和你視頻";
                showLabel.textColor = RGBA(142, 74, 255, 1.0);
                
                NSMutableArray *ary=[NSMutableArray new];
                for(int I=1;I<=7;I++){
                    NSString *imageName=[NSString stringWithFormat:@"showGif%d",I];
                    UIImage *image=[UIImage imageNamed:imageName];
                    [ary addObject:image];
                }
                view.animationImages=ary;
                view.animationRepeatCount=0;
                view.animationDuration=1.0;
                [view startAnimating];
            }
            
            if ([dictionary[@"fromContactid"] integerValue] == 2) {
                
                showLabel.text = @"她距離你較近";
                showLabel.textColor = [UIColor redColor];
                
                NSMutableArray *ary=[NSMutableArray new];
                for(int I=1;I<=3;I++){
                    NSString *imageName=[NSString stringWithFormat:@"gifImage%d",I];
                    UIImage *image=[UIImage imageNamed:imageName];
                    [ary addObject:image];
                }
                view.animationImages=ary;
                view.animationRepeatCount=0;
                view.animationDuration=1.0;
                [view startAnimating];
            }
        
        }
        
        //cell復(fù)用問題
        for (UIView *view in baseCell.contentView.subviews) {
            if ([dictionary[@"fromContactid"] integerValue] == 0 && [view isKindOfClass:UIImageView.class] && view.tag == 120) {
                [view removeFromSuperview];
            }
            if ([dictionary[@"fromContactid"] integerValue] == 0 && [view isKindOfClass:UILabel.class] && view.tag == 110) {
                [view removeFromSuperview];
            }
        }
        
    } else {
        
        //cell復(fù)用問題
        for (UIView *view in baseCell.contentView.subviews) {
            if ([view isKindOfClass:UIImageView.class] && view.tag == 120) {
                [view removeFromSuperview];
            }
            if ([view isKindOfClass:UILabel.class] && view.tag == 110) {
                [view removeFromSuperview];
            }
        }
        
    }
    
    [cell layoutIfNeeded];
    
}

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子尿赚,更是在濱河造成了極大的恐慌察皇,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,888評(píng)論 6 515
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件旅掂,死亡現(xiàn)場(chǎng)離奇詭異赏胚,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)商虐,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,677評(píng)論 3 399
  • 文/潘曉璐 我一進(jìn)店門觉阅,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人秘车,你說我怎么就攤上這事典勇。” “怎么了鲫尊?”我有些...
    開封第一講書人閱讀 168,386評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵痴柔,是天一觀的道長。 經(jīng)常有香客問我疫向,道長咳蔚,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 59,726評(píng)論 1 297
  • 正文 為了忘掉前任搔驼,我火速辦了婚禮谈火,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘舌涨。我一直安慰自己糯耍,他們只是感情好,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,729評(píng)論 6 397
  • 文/花漫 我一把揭開白布囊嘉。 她就那樣靜靜地躺著温技,像睡著了一般。 火紅的嫁衣襯著肌膚如雪扭粱。 梳的紋絲不亂的頭發(fā)上舵鳞,一...
    開封第一講書人閱讀 52,337評(píng)論 1 310
  • 那天,我揣著相機(jī)與錄音琢蛤,去河邊找鬼蜓堕。 笑死抛虏,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的套才。 我是一名探鬼主播迂猴,決...
    沈念sama閱讀 40,902評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼背伴!你這毒婦竟也來了沸毁?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 39,807評(píng)論 0 276
  • 序言:老撾萬榮一對(duì)情侶失蹤挂据,失蹤者是張志新(化名)和其女友劉穎以清,沒想到半個(gè)月后,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體崎逃,經(jīng)...
    沈念sama閱讀 46,349評(píng)論 1 318
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡掷倔,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,439評(píng)論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了个绍。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片勒葱。...
    茶點(diǎn)故事閱讀 40,567評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖巴柿,靈堂內(nèi)的尸體忽然破棺而出凛虽,到底是詐尸還是另有隱情,我是刑警寧澤广恢,帶...
    沈念sama閱讀 36,242評(píng)論 5 350
  • 正文 年R本政府宣布凯旋,位于F島的核電站,受9級(jí)特大地震影響钉迷,放射性物質(zhì)發(fā)生泄漏至非。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,933評(píng)論 3 334
  • 文/蒙蒙 一糠聪、第九天 我趴在偏房一處隱蔽的房頂上張望荒椭。 院中可真熱鬧,春花似錦舰蟆、人聲如沸趣惠。這莊子的主人今日做“春日...
    開封第一講書人閱讀 32,420評(píng)論 0 24
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽味悄。三九已至,卻和暖如春塌鸯,著一層夾襖步出監(jiān)牢的瞬間傍菇,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 33,531評(píng)論 1 272
  • 我被黑心中介騙來泰國打工界赔, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留丢习,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,995評(píng)論 3 377
  • 正文 我出身青樓淮悼,卻偏偏與公主長得像咐低,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子袜腥,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,585評(píng)論 2 359

推薦閱讀更多精彩內(nèi)容