0

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をクリックすると、行を削除することしかできず、並べ替えることはできません。エラーが発生したときは?つまり、右側のセルの側に並べ替えアイコンはありません。

4

1 に答える 1

1

わかりました、私はそれを解決しました。

並べ替えコントロールを表示するには、このプロパティを設定するだけでなく、UITableViewDataSource メソッド tableView:moveRowAtIndexPath:toIndexPath: を実装する必要があります。さらに、データ ソースが tableView:canMoveRowAtIndexPath: を実装して NO を返す場合、並べ替えコントロールはその指定された行に表示されません。

于 2012-09-20T22:09:39.010 に答える