構築されたものと同じように、単純なメッセージングアプリを作成しようとしています。
と同じ効果の吹き出しを再現したいiMessage
。
その機能を持つMultipeerGroupChatと呼ばれるアップルのプロジェクトを見つけました。
問題は、クラスの依存関係のために、必要以上に複製が困難になっていることです。マルチピアや画像の送信は必要ありません。すでに多くのコードを取り除いています。
シンプルな ができTableView
ました。バブル画像と 2 つのクラスを追加しました。
MessageView.h
Transcript.h
バブルを表示するために、このテーブル ビュー デリゲートに問題を絞り込みました。
// The individual cells depend on the type of Transcript at a given row. We have 3 row types (i.e. 3 custom cells) for text string messages, resource transfer progress, and completed image resources
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
// Get the transcript for this row
Transcript *transcript = [self.transcripts objectAtIndex:indexPath.row];
// Check if it's an image progress, completed image, or text message
UITableViewCell *cell;
if (nil != transcript.imageUrl) {
// It's a completed image
cell = [tableView dequeueReusableCellWithIdentifier:@"Image Cell" forIndexPath:indexPath];
// Get the image view
ImageView *imageView = (ImageView *)[cell viewWithTag:IMAGE_VIEW_TAG];
// Set up the image view for this transcript
imageView.transcript = transcript;
}
else if (nil != transcript.progress) {
// It's a resource transfer in progress
cell = [tableView dequeueReusableCellWithIdentifier:@"Progress Cell" forIndexPath:indexPath];
ProgressView *progressView = (ProgressView *)[cell viewWithTag:PROGRESS_VIEW_TAG];
// Set up the progress view for this transcript
progressView.transcript = transcript;
}
else {
// Get the associated cell type for messages
cell = [tableView dequeueReusableCellWithIdentifier:@"Message Cell" forIndexPath:indexPath];
// Get the message view
MessageView *messageView = (MessageView *)[cell viewWithTag:MESSAGE_VIEW_TAG];
// Set up the message view for this transcript
messageView.transcript = transcript;
}
return cell;
}
前に述べたように、メッセージだけが必要なので、次のように省略しました。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell;
Transcript *transcript = [self.messageArray objectAtIndex :[indexPath row]];
cell = [tableView dequeueReusableCellWithIdentifier:@"Message Cell" forIndexPath:indexPath];
MessageView *messageView = (MessageView *)[cell viewWithTag:MESSAGE_VIEW_TAG];
messageView.transcript = transcript;
//how does the code add the view and return it ?? :-S
return cell;
}
このコードは何も表示しません。
このコードがセルをカスタマイズして吹き出しを表示する方法がわかりません。
ご意見をお聞かせください。