4

iOSプロジェクトの場合、ユーザーが選択した行をドラッグして移動できるようにするのは比較的簡単です。のようなものだと思います

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{
    return UITableViewCellEditingStyleNone;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (BOOL)tableView:(UITableView *)tableview canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
    // ...
}

セルベースのテーブルがある場合、 Mac OSでNSTableView (iOS の UITableView ではない)をどのように使用しますか? ユーザーが項目をドラッグできるようにする Apple, Inc. のサンプル プロジェクトの 1 つがimage-browser です。NSTableView コントロールが含まれていないため、あまり役に立ちません。canDragRowsWithIndexes :atPointを使用していますか? canDragRowsWithIndexes で検索があまりヒットしません。「NSTableView 並べ替え」で検索すると、テーブル項目の並べ替えがヒットします。

アドバイスありがとうございます。

4

1 に答える 1

3

次の方法を使用します。

- (BOOL)tableView:(NSTableView *)aTableView acceptDrop:(id < NSDraggingInfo >)info row:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation

- (NSDragOperation)tableView:(NSTableView *)aTableView validateDrop:(id < NSDraggingInfo >)info proposedRow:(NSInteger)row proposedDropOperation:(NSTableViewDropOperation)operation

- (BOOL)tableView:(NSTableView *)aTableView writeRowsWithIndexes:(NSIndexSet *)rowIndexes toPasteboard:(NSPasteboard *)pboard

Corbin Dunn によるこのガイドは少し古いですが、うまく理解できるはずです。

于 2013-06-05T12:50:14.123 に答える