で設定UITableViewを複数選択的なのか?
-
08-07-2019 - |
質問
IPhoneにすることはできるかを設定すUITableViewようにすることにより複数選択的なのか?
思ったよりも優 -setSelected:animated:
各UITableViewCellもうファッジ、必要な行動が難しい別のunselectionsからのUITableViewと考えるか選択解除によって、他の細胞!
希望の人のお役に立つことでしょ
おかげさ
ブランド。
解決
これを行う最良の方法は、選択した行ごとにチェックマークを付けることです。
選択するには、選択したUITableViewCellインスタンスのaccessoriesTypeをUITableViewCelAccessoryCheckmarkに設定します。
行の選択を解除するには、UITableViewCellAccessoryNoneに戻します。
選択されたセル/行を列挙するには(ボタンをクリックしたときなど)、UITableViewCellAccessoryCheckmarkを探してテーブルのセルを単純に繰り返します。または、「did select」でテーブルビューデリゲートのNSSetなどを管理します。デリゲートメソッド。
他のヒント
iOS5.0以降向けのアプリを開発している場合、次のプロパティは正常に機能するはずです
self.tableView.allowsMultipleSelection = YES;
次のコードを使用して、セルアクセサリタイプを設定します。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *thisCell = [tableView cellForRowAtIndexPath:indexPath];
if (thisCell.accessoryType == UITableViewCellAccessoryNone) {
thisCell.accessoryType = UITableViewCellAccessoryCheckmark;
}else{
thisCell.accessoryType = UITableViewCellAccessoryNone;
}
}
- (UITableViewCellAccessoryType)tableView:(UITableView *)tableView accessoryTypeForRowWithIndexPath:(NSIndexPath *)indexPath {
//add your own code to set the cell accesory type.
return UITableViewCellAccessoryNone;
}
Jeff Lamarcheには、これを行う方法に関するチュートリアルがあります:
http://iphonedevelopment.blogspot。 com / 2008/10 / table-view-multi-row-edit-mode.html
コードを試したことはありませんが、必要な日が来ることを知っているので、しばらく気になりませんでした。
allowsMultipleSelectionDuringEditing
および allowsMultipleSelection
をiOS5から古いiOSにバックポートしました。 https://github.com/ud7/UDTableView-allowsMultipleSelection
代わりにドロップインするだけで、UITableViewをUDTableViewに変更するだけです(コードまたはインターフェイスビルダーで)
HIGから:
テーブルビューは、ユーザーがリストアイテムを選択したときにフィードバックを提供します。具体的には、アイテムを選択できる場合、 ユーザーが項目を選択すると、その項目を含む行が一時的に強調表示され、選択が受信されたことを示します。 次に、すぐにアクションが発生します。新しいビューが表示されるか、行にチェックマークが表示されます。 アイテムが選択されたこと。テーブルビューには表示されないため、行は強調表示されたままになりません。 永続的な選択状態。
メールのようなものを使用するか、セルにチェックマークアクセサリを使用して、独自の複数選択スタイルをロールする必要があります。
必要な複数選択のガイド
self.tableView.allowsMultipleSelection = YES;
viewDidLoadおよび
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryView.hidden = NO;
// if you don't use custom image tableViewCell.accessoryType = UITableViewCellAccessoryCheckmark;
}
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *tableViewCell = [tableView cellForRowAtIndexPath:indexPath];
tableViewCell.accessoryView.hidden = YES;
// if you don't use custom image tableViewCell.accessoryType = UITableViewCellAccessoryNone;
}
Mailの複数選択(たとえば、メールを削除する)のようなことをしようとしている場合、おそらくすべての選択を自分で管理する必要があります。複数行の選択は、iPhoneの標準的なものではありません。 Mailは、チェックマークを使用して選択されている行を示すことでこれを解決します。
HIG ページ121。チェックマークで問題を解決できます。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
int selectedRow = indexPath.row;
cout << "selected Row: " << selectedRow << endl;
UITableViewCell *indexPathForCell = [tableView cellForRowAtIndexPath:indexPath];
if (indexPathForCell.accessoryType == UITableViewCellAccessoryNone) {
indexPathForCell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
indexPathForCell.accessoryType = UITableViewCellAccessoryNone;
}
}
次に、配列を追加するか、選択されたデータを保存する方法を追加します。
いたるとともに、同誌掲載号の注目とその回答のBhavin Chitroda sovledけてはいけませんが、このチェックマークしていましたがスクロールします。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if ( [array indexOfObject:indexPath] == NSNotFound ) {
[array addObject:indexPath];
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
[array removeObject:indexPath];
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
追加:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
// Your code here
.
.
.
if ( [array indexOfObject:indexPath] == NSNotFound ) {
cell.accessoryType = UITableViewCellAccessoryNone;
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
return cell;
}
注:これはiOS 4以降では機能しません。これは、ドキュメント化されていないプライベートな定数です。使用しないでください。
アプリをApp Storeに送信する予定がない場合は、UITableViewControllerデリゲートで次のメソッドを実装することにより、複数行編集モードを呼び出すことができます。
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
return 3; // Undocumented constant
}
iOS4.3-6.0でテスト済み
-(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {
if ([controller.searchResultsTableView respondsToSelector:@selector(allowsMultipleSelectionDuringEditing)]) {
controller.searchResultsTableView.allowsMultipleSelectionDuringEditing = YES;
}
else {
controller.searchResultsTableView.allowsSelectionDuringEditing = YES;
}
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellAccessoryCheckmark;
}