にバブル(セル)をチャットするサブビューを追加します。私はメッセージを送受信できます。私は<em>アレックスbarinovの</em>チャットバブルの例を使用しています<strong>チャットアプリケーション</strong>に取り組んでいますiOSの
-(void)setupInternalData
という名前のメソッドでUIBubbleTableViewCell.m
クラスのチャットバブルのcontentViewにいくつかのラベルを追加しようとしましたが、ラベル(dateラベル)がバブルごとに繰り返され、前のラベルが上書きされ、両方のラベルが含まれます。ここで
は私がプロジェクトをダウンロードした場所からのアドレスである - https://github.com/AlexBarinov/UIBubbleTableView以下
はバブルビューをチャットにラベルを追加するための私のコードです -
-(void)setupInternalData{
_fromLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.frame.origin.x, self.frame.size.height-28, 100, 14)];
_fromLabel.numberOfLines = 1;
_fromLabel.baselineAdjustment = UIBaselineAdjustmentAlignBaselines;
_fromLabel.clipsToBounds = YES;
_fromLabel.layer.cornerRadius=5;
[_fromLabel setFont:[UIFont systemFontOfSize:5]];
[self.customView addSubview:_fromLabel];
//display msg sent time
NSDate *today = [NSDate date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setTimeStyle:NSDateFormatterShortStyle];
[dateFormatter setDateStyle:NSDateFormatterMediumStyle];
NSString *currentTime = [dateFormatter stringFromDate:today];
_lblMsgTime.text=currentTime;
_lblMsgTime.frame=CGRectMake(12,0, 85, 14);
_lblMsgTime.text=[NSString stringWithFormat:@"%@",currentTime];
_lblMsgTime.textAlignment = NSTextAlignmentRight;
_lblMsgTime.textColor = [UIColor blackColor];
[_fromLabel addSubview:_lblMsgTime];
[_lblMsgTime setAdjustsFontSizeToFitWidth:YES];
//date formater
NSDate *date = [NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"d.M.yyyy";
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateStyle:NSDateFormatterMediumStyle];
NSString *string = [formatter stringFromDate:date];
_lblMsgdate.text=string;
_lblMsgdate.frame=CGRectMake(60 ,0, 85, 14);
_lblMsgdate.text=[NSString stringWithFormat:@"%@",string];
_lblMsgdate.textAlignment = NSTextAlignmentRight;
_lblMsgdate.textColor = [UIColor blackColor];
[_fromLabel addSubview:_lblMsgdate];
[_lblMsgdate setAdjustsFontSizeToFitWidth:YES];
UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ic__typ__txt.png"]];
backgroundView.frame=CGRectMake(self.frame.origin.x+1, self.frame.size.height-24, 10, 10);
[self.customView addSubview:backgroundView];
[self.customView bringSubviewToFront:_fromLabel];
[self.customView bringSubviewToFront:backgroundView];
[self.contentView addSubview:self.customView];
}
誰もが間違っている私がここでやっているものを私に教えてくださいすることができ私は何をしているのですか?どんな助けもありがとうございます。あなたの貴重な答えを待っています。
別々のメソッドではなく、初期化子からサブビューを追加して追加し、別の場所から呼び出します。 –
@ Rohan Bhale - 私はiOSを初めて使っているので、これについて詳しく説明してください。上記のコードを正確に追加する場所お願いします。 –
https://github.com/jessesquires/JSQMessagesViewController –