2011-06-22 9 views
0

私はiPhone用のチャットアプリのようなことをしています.Sam SoffesのこのコードはSSMessagesViewControllerと呼ばれています。テーブルには多くの行があるまで完全に機能することがわかりましたDrawureは、6行ごとに同じ行の内容を繰り返すため、セルを再利用しています(ただし、データは異なります)...どうすればその問題を解決できますか?iChatのようなUITableViewCell風船

- (void)drawRect:(CGRect)frame { 
    UIImage *bubbleImage = _messageStyle == SSMessageStyleLeft ? _leftBackgroundImage : _rightBackgroundImage; 
    CGSize bubbleSize = [[self class] bubbleSizeForText:_messageText]; 
    CGRect bubbleFrame = CGRectMake((_messageStyle == SSMessageStyleRight ? self.frame.size.width - bubbleSize.width : 0.0f), kMarginTop, bubbleSize.width, bubbleSize.height); 
    [bubbleImage drawInRect:bubbleFrame]; 

    CGSize textSize = [[self class] textSizeForText:_messageText]; 
    CGFloat textX = (CGFloat)bubbleImage.leftCapWidth - 3.0f + ((_messageStyle == SSMessageStyleRight) ? bubbleFrame.origin.x : 0.0f); 
    CGRect textFrame = CGRectMake(textX, kPaddingTop + kMarginTop, textSize.width, textSize.height); 
    [_messageText drawInRect:textFrame withFont:kFont lineBreakMode:kLineBreakMode alignment:(_messageStyle == SSMessageStyleRight) ? UITextAlignmentRight : UITextAlignmentLeft]; 
} 

答えて

0

この段階では、2つの画像があります。左のバブル画像と右のバブル画像は、レイヤーに画像を追加することが可能です。 2つのセルが1つ左を指し、もう1つが右を指していると想像してください。あなたはTableCellをサブクラス化する必要があります。カスタムスタイルを定義し、割り当てられたスタイル値に応じて、追加したBackroundビューのサブレイヤにこれらのイメージを追加できます(exulticitly added)。 http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Articles/ProvidingCALayerContent.html また、1つのことを行います。メソッドlayoutsubviewsをオーバーライドします。 CALayers didn't get resized on its UIView's bounds change. Why?その例。 この時点で、BackgroundViewのサブレイヤのサイズをテーブルのセルのサイズにリセットします。今すぐあなたはdelgateメソッドでTablecellheightをsepcifyする必要がありますhttp://developer.apple.com/library/ios/documentation/uikit/reference/UITableViewDelegate_Protocol/Reference/Reference.html#//apple_ref/doc/uid/TP40006942-CH3-SW25

関連する問題