簡體   English   中英

SwiftUI List onDelete IndexSet to int

[英]SwiftUI List onDelete IndexSet to int

如何將偏移量:IndexSet 值轉換為純 int?

我可以使用 offsets.startIndex 獲得一個范圍,但這仍然沒有給我一個 int。 startIndex 似乎是我需要傳遞給視圖 model 的值,以便我可以更新底層數組。

您可以通過 IndexSet 循環獲取用戶觸發刪除的數組的特定索引。

        .onDelete {indexSet in
            for index in indexSet{
                print(index)
            }
        }

只有一個元素索引將被刪除數組的索引。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM