UITableView のヘルプが必要です。編集テーブル機能を作成するための最適なソリューションを探しています。データと 2 つのモードを備えた UITableViewController があります。
- 編集モード: すべてのフィールド (姓、名、電話番号、Web ページなど)
- 表示モード: フィールド化された行のみを表示します。
難しいのは、ユーザーが編集ボタンをクリックしたときに行をアニメーション化することです。
iPhone のアドレス帳アプリと同じアニメーションが必要です。
UITableView のヘルプが必要です。編集テーブル機能を作成するための最適なソリューションを探しています。データと 2 つのモードを備えた UITableViewController があります。
難しいのは、ユーザーが編集ボタンをクリックしたときに行をアニメーション化することです。
iPhone のアドレス帳アプリと同じアニメーションが必要です。
解決策があります! この記事のヘルプ
したがって、このようなものを追加する必要があります(サンディに感謝します)
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
[super setEditing:editing animated:animated];
NSArray *paths = [NSArray arrayWithObject:
[NSIndexPath indexPathForRow:1 inSection:0]];
if (editing) {
[[self tableView] insertRowsAtIndexPaths:paths
withRowAnimation:UITableViewRowAnimationTop];
}else {
[[self tableView] deleteRowsAtIndexPaths:paths
withRowAnimation:UITableViewRowAnimationTop];
}
}
その後 - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
が収集され、セルのリストとその外観を編集できます。
シンプルにこんな感じ。
//original position and maybe hidden
someView.frame = CGRect(0,0,0,0);
someView.alpha = 0.0f;
[someView setHidden:YES];
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
//what you want it comes out finally, changed position and visible
[someView setHidden:NO];
someView.frame = CGRect(100.0f,100.0f,0,0);
someView.alpha = 1.0f;
[UIView commitAnimations];
使用する
[tableView setEditing: YES animated: YES];
編集モードでUItableViewを作成します。行をスワイプするとボタンを表示および非表示にできます。アニメーションが何かある場合はお知らせください。
以下の例では、2 つのセクションがあり、最初のセクションには一連の設定が含まれています。最初の行はデフォルト設定で、常にそこにあり、並べ替えることはできません。2 番目の行には、「追加...」などの 1 つの行のみが含まれています。並べ替えと削除専用なので、編集モードでは最初の設定を削除し、2 番目のセクションを削除します。テーブルビューの beginUpdates/endUpdates 内ですべての挿入/削除を行うと、スムーズにアニメーション化されます。したがって、編集時に行/セクションを追加するのは正反対です。
通常モードでは、次のものがあります。
Countries (<-- 1st section)
- World
- Argentina
- USA
(<-- 2nd section)
- Add Countries...
編集モードでは、次のものがあります。
Countries (<-- 1st section)
- Argentina = (can be removed/reordered)
- USA = (can be removed/reordered)
コードは次のようになります。
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
NSArray *paths = [NSArray arrayWithObjects:
[NSIndexPath indexPathForRow:0 inSection:0],
nil];
[self.tableView beginUpdates]; // Club all updates together
if (editing)
{
if( [[CCPollSettings countryCodes] count] < 2) // No country setting
// Remove complete section
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
else // Remove first default row
[self.tableView deleteRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
// Remove 'Add...' Section
[self.tableView deleteSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
// .... Do more stuff after
} else {
if( [[CCPollSettings countryCodes] count] < 2) // No country setting yet
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationFade];
else // add back default row
[self.tableView insertRowsAtIndexPaths:paths withRowAnimation:UITableViewRowAnimationFade];
// Add back 'Add...' Section
[self.tableView insertSections:[NSIndexSet indexSetWithIndex:1] withRowAnimation:UITableViewRowAnimationFade];
}
[self.tableView endUpdates]; // Club all updates together
}