UITableViewでセルをリオーダーできるように約1時間試します。
私は細胞を作る
-(UITableViewCell *)tableView:(UITableView *)tV cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tV dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}
// Set up the cell...
cell.textLabel.text = [array objectAtIndex:indexPath.row];
cell.showsReorderControl = YES;
return cell;
}
そして私はこれを持っています:
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
とボタン方式
- (IBAction)delete:(id)sender {
if (self.btnLeft.tag == 0) {
self.btnLeft.title = @"Zakończ";
[self.tableView setEditing:YES animated:YES];
self.btnLeft.tag = 1;
}
else if (self.btnLeft.tag == 1) {
self.btnLeft.title = @"Edytuj";
[self.tableView setEditing:NO animated:YES];
self.btnLeft.tag = 0;
}
}
しかし、編集ボタン isetEditing to YES
をクリックすると、行を削除することしかできず、並べ替えることはできません。エラーが発生したときは?つまり、右側のセルの側に並べ替えアイコンはありません。