SwiftUI,从场景更改视图(:continue

时间:2020-08-14 03:15:51

标签: ios swift swiftui uiscenedelegate

SwiftUI应用中,我面临着新的挑战,希望有人能给我一些提示或指导。到目前为止,我所看到的在应用程序各部分之间进行通信的机制似乎不太适合。但这可能是由于我在SwiftUI方面的经验仍然有限。

首先是相关代码:

class SceneDelegate {
  ... lot of code irrelevant to the question ...
  func scene(_ scene: UIScene, 
             continue userActivity: NSUserActivity) {
      ... useful things happening for the app ...
      // Now the view should change ... by some mechanism.
      // This is the point of the question.
  }
}

和:

struct ContentView: View {
    ... lot of code irrelevant to the question ...
    var body: some View {
        VStack {
          ... code to draw the view ...
        }
        ... more code to draw the view ...
    }
}

第二,我的问题是: scene(:continue?

我想到了一些想法,以便在 scene(:continue )函数中执行可能会影响视图绘制的事情。

不幸的是,当尝试实现时,我意识到绘制视图的代码是在 scene(:continue 函数之前执行的。因此,我需要其他机制(通知之类的,绑定之类的? )重新绘制视图。

是否有好的做法或标准方法?

1 个答案:

答案 0 :(得分:2)

在这种情况下使用[ { "id": 4379711799354, "variant_id": 31291380727866, "title": "*NEW* Kayslin Sneaker in Blush", "quantity": 1, "sku": "79000212", "variant_title": "3Y", "vendor": "TESTVENDOR", "fulfillment_service": "manual", "product_id": 4371426607162, "requires_shipping": true, "taxable": true, "gift_card": false, "name": "*NEW* Kayslin Sneaker in Blush - 3Y", "variant_inventory_management": "shopify", "properties": [ { "name": "Item Ships Separately", "value": "✓" } ], "product_exists": true, "fulfillable_quantity": 0, "grams": 490, "price": "68.00", "total_discount": "0.00", "fulfillment_status": "fulfilled", "pre_tax_price": "68.00", "price_set": { "shop_money": { "amount": "68.00", "currency_code": "USD" }, "presentment_money": { "amount": "68.00", "currency_code": "USD" } }, "pre_tax_price_set": { "shop_money": { "amount": "68.00", "currency_code": "USD" }, "presentment_money": { "amount": "68.00", "currency_code": "USD" } }, "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "USD" }, "presentment_money": { "amount": "0.00", "currency_code": "USD" } }, "discount_allocations": [], "admin_graphql_api_id": "gid:\/\/shopify\/LineItem\/4379711799354", "tax_lines": [ { "title": "CT STATE TAX", "price": "0.00", "rate": 0.0, "price_set": { "shop_money": { "amount": "0.00", "currency_code": "USD" }, "presentment_money": { "amount": "0.00", "currency_code": "USD" } } } ], "origin_location": { "id": 624876322874, "country_code": "US", "province_code": "TX", "name": "Joyfolie", "address1": "1809 W Frankford Rd #160 ", "address2": "", "city": "Carrollton", "zip": "75007" } }, { "id": 4379711832122, "variant_id": 31031946838074, "title": "*NEW* Mama Bird Necklace Set in Gold", "quantity": 1, "sku": "83000109", "variant_title": "", "vendor": "TESTVENDOR", "fulfillment_service": "manual", "product_id": 4320751878202, "requires_shipping": true, "taxable": true, "gift_card": false, "name": "*NEW* Mama Bird Necklace Set in Gold", "variant_inventory_management": "shopify", "properties": [], "product_exists": true, "fulfillable_quantity": 0, "grams": 113, "price": "29.50", "total_discount": "0.00", "fulfillment_status": "fulfilled", "pre_tax_price": "29.50", "price_set": { "shop_money": { "amount": "29.50", "currency_code": "USD" }, "presentment_money": { "amount": "29.50", "currency_code": "USD" } }, "pre_tax_price_set": { "shop_money": { "amount": "29.50", "currency_code": "USD" }, "presentment_money": { "amount": "29.50", "currency_code": "USD" } }, "total_discount_set": { "shop_money": { "amount": "0.00", "currency_code": "USD" }, "presentment_money": { "amount": "0.00", "currency_code": "USD" } }, "discount_allocations": [], "admin_graphql_api_id": "gid:\/\/shopify\/LineItem\/4379711832122", "tax_lines": [ { "title": "CT STATE TAX", "price": "0.00", "rate": 0.0, "price_set": { "shop_money": { "amount": "0.00", "currency_code": "USD" }, "presentment_money": { "amount": 是合适的

EnvironmentObject