私は周りを探索してきましたが、私が直面しているこの特定の問題に対する答えを見つけることができないようです。これは私が実験している一般的なチャットアプリです。私の目的は、単一のconvoまたはグループconvoの場合にのみ、特定のセクションを表示することです。あなたは特定のセクションを表示
#define bGroupNameSection 0
#define bParticipantsSection 1
#define bAddParticipantSection 2
#define bLeaveConvoSection 3
#define bSectionCount 4
以下のコード上で見ることができるように、何が現在やっていることは私的な会話やグループチャットの両方にbGroupNameSectionある最初のセクションが表示されています。しかし、私はそれが私的な会話であるかどうかを示すために参加者セクションだけを望みます。
ここでは、何を意味するのかを理解するのに役立つスクリーンショットを示します。
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
//to check if its a group or single chat and to return the amount of sections.
return _thread.type.intValue == bThreadTypePrivateGroup ? bSectionCount : 1;
}
私はここ
if(it is a private chat) {
// make bParticipantsSection 0
bAddParticipantSection 1
bLeaveConvoSection 2
bSectionCount 3
remove bGroupNameSection
}
を助けるかもしれない他の関連するコードとなる条件ここでチェックの任意のフォームを行うことができアム。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if (section == bParticipantsSection) {
return _users.count ? _users.count : 1;
}
if (section == bLeaveConvoSection || section == bAddParticipantSection || section == bGroupNameSection) {
return 1;
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView_ cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell * cell = [tableView_ dequeueReusableCellWithIdentifier:bCell];
cell.textLabel.textColor = [UIColor blackColor];
if (indexPath.section == bParticipantsSection) {
if (_users.count) {
CGSize itemSize = CGSizeMake(0, 0);
id<PUser> user = _users[indexPath.row];
cell.textLabel.text = user.name;
cell.imageView.image = user && user.thumbnail ? [UIImage imageWithData:user.thumbnail] : [NSBundle chatUIImageNamed: @"icn_user.png"];
cell.imageView.layer.cornerRadius = 20;
cell.imageView.clipsToBounds = YES;
itemSize = CGSizeMake(40, 40);
UIGraphicsBeginImageContextWithOptions(itemSize, NO, UIScreen.mainScreen.scale);
CGRect imageRect = CGRectMake(0.0, 0.0, itemSize.width, itemSize.height);
[cell.imageView.image drawInRect:imageRect];
cell.imageView.image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
else {
cell.textLabel.text = [NSBundle t:bNoActiveParticipants];
cell.imageView.image = nil;
}
cell.textLabel.textAlignment = _users.count ? NSTextAlignmentLeft : NSTextAlignmentCenter;
cell.selectionStyle = _users.count ? UITableViewCellSelectionStyleDefault :UITableViewCellSelectionStyleNone;
return cell;
}
if (indexPath.section == bAddParticipantSection) {
// Reset the image view
cell.imageView.image = nil;
cell.textLabel.textAlignment = NSTextAlignmentCenter;
cell.textLabel.text = [NSBundle t:bAddParticipant];
}
if (indexPath.section == bLeaveConvoSection) {
// Reset the image view
cell.imageView.image = nil;
cell.textLabel.text = [NSBundle t:bLeaveConversation];
cell.textLabel.textColor = [UIColor redColor];
cell.textLabel.textAlignment = NSTextAlignmentCenter;
}
if (indexPath.section == bGroupNameSection) {
UITextField *groupNameTextField = [[UITextField alloc]initWithFrame:CGRectMake(10,10, 300, 30)];
groupNameTextField.delegate = self;
groupNameTextField.returnKeyType = UIReturnKeyDone;
groupNameTextField.clearButtonMode = UITextFieldViewModeWhileEditing;
groupNameTextField.text = _thread.displayName;
[cell.contentView addSubview:groupNameTextField];
}
return cell;
}
特定の問題点を明確にすることはできますか?これらのスクリーンショットが望ましい機能であるか間違っている機能であるかは明らかではなく、実際に何が実際に行われているかを識別するためのコンテキストもありません。 – Stonz2
こんにちは@ stonz2最初のスクリーンショットにはグループチャットの詳細が表示され、そのセクションはどのように表示され、2番目はプライベートな会話の詳細がどのように見えるか、3番目はプライベートな会話の様子です。私は、参加者セクションが "グループ名"セクションではなく、表示されることを望みます。 – Venus007