4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftUIでScrollViewが更新されない時の対処法

Posted at

ScrollView(ForEach)で参照している配列の値をCombineを使って動的に更新した際に、Viewが反映されない事象が起きた。
データの送受信でバグがあるのかとも考えたが、Listにしたところ問題なく反映されたので色々調べたがピンポイントな解決策がなかなか見つからなかったのでQiitaにも残しておく。

環境

Xcode 11.3(11C29)

解決策

結果的に空配列ではなく、なにかしらの初期値をセットしておくことで動的に更新されるようになった。

@Published var items: [String] = [""]

以下のStack Overflowの回答で解決した :pray:

ios - SwiftUI ForEach not correctly updating in scrollview - Stack Overflow
https://stackoverflow.com/questions/59316078/swiftui-foreach-not-correctly-updating-in-scrollview

--

4
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?