0

次のコードで試しました。それは正常に動作します。しかし、いくつかのことを達成する方法がわかりません。

スクリーンショット

  1. 同じ行の削除コントロールの代わりに「削除」ボタンをクリックしたときに挿入コントロールを追加するにはどうすればよいですか?

  2. 「セクション 3」を「セクション 1」と「セクション 2」の間に移動した場合、3 つのセクションすべてを削除コントロールで更新するにはどうすればよいですか?

これまでのところ、以下のコードを使用して次の出力を得ています。

    -(void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {

    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //Handle things when deletion control clicked!

        //[sectionArray removeObjectAtIndex:indexPath.row];
        //[self.tableView reloadData];
    } else if (editingStyle == UITableViewCellEditingStyleInsert) {
        //Handle things when insertion control clicked!
    }
}


    - (UITableViewCellEditingStyle)tableView:(UITableView *)aTableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    // No editing style if not editing or the index path is nil.
    if (isEditMode == NO || !indexPath) return UITableViewCellEditingStyleNone;
    if (indexPath.row == 1){
        return UITableViewCellEditingStyleDelete;
    }else if (indexPath.row == 2){
        return UITableViewCellEditingStyleInsert;
    }else if (indexPath.row == 3){
        return UITableViewCellEditingStyleInsert;
    }else {
        return UITableViewCellEditingStyleDelete;
    }
    return UITableViewCellEditingStyleNone;
}

    - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
      toIndexPath:(NSIndexPath *)toIndexPath {
    NSString *item = [sectionArray objectAtIndex:fromIndexPath.row];
    [sectionArray removeObject:item];
    [sectionArray insertObject:item atIndex:toIndexPath.row];

    NSLog(@"%@", sectionArray);
}
4

2 に答える 2

0

このリンクもお役に立てば幸いです。

http://code4app.net/ios/UITableView-actions/50bf05986803fa8e5c000001

http://www.appcoda.com/model-view-controller-delete-table-row-from-uitableview/

UI の問題が発生した場合はいつでも、こちら側からデモ アプリケーションも入手できます。

http://code4app.net

于 2013-09-20T09:19:41.837 に答える