【问题标题】:How to rearrange table after deleting first row in sqlite?删除sqlite中的第一行后如何重新排列表格?
【发布时间】:2011-08-29 09:13:39
【问题描述】:

我在 sqlite 中有 1 个表,我正在向该表插入值。当插入行 id 大于 100 时,我想删除第一个插入的记录并在第 100 个位置插入新记录,我删除了第 1 条记录,但第 2 条记录在第 2 位,但我想在删除第一行后重新排列记录。我该怎么做?

我的表名是:Products

我的表包含 productName,productId,...

我的数据库名称是:HalalGauge.sqlite

【问题讨论】:

    标签: iphone xcode sqlite


    【解决方案1】:

    将您的新行添加为 productId 101。 从 productId = 1 的产品中删除 更新产品集 productId = (productId-1)

    我不会称这是一个很好的解决方案,因为它会更新每一行,但如果你只有 100 行就可以了。

    【讨论】:

    • 我的应用程序中的 ProductID 提供随机值我可以使用 rowid 代替吗?
    • DELETE FROM PRODUCTS WHERE rowID = 1 UPDATE PRODUCTS set rowID = (rowID-1) 是否正确?
    【解决方案2】:

    你需要使用这个方法来重新排列

    - (void)tableView:(UITableView *)tableView
             commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
             forRowAtIndexPath:(NSIndexPath *)indexPath;
    
    - (void)tableView:(UITableView *)tableView
             moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
             toIndexPath:(NSIndexPath *)toIndexPath;
    

    【讨论】:

      猜你喜欢
      • 2016-01-21
      • 1970-01-01
      • 1970-01-01
      • 2021-05-07
      • 2017-07-09
      • 1970-01-01
      • 2015-04-06
      • 1970-01-01
      • 2017-08-31
      相关资源
      最近更新 更多