LoginSignup
5
2

More than 3 years have passed since last update.

【謎すぎ】SwiftUI encountered an issue when pushing aNavigationLink エラー

Posted at

謎すぎる「SwiftUI encountered an issue when pushing aNavigationLink」

以下のバグにだいぶ苦しみました。

一応画面遷移はちゃんとできるし、一見問題なさそうだけどエラーログ出ているのが気持ち悪かったので対応した。どうせアプリリースの時にappleさんから指摘されそうだしね。

SwiftUI encountered an issue when pushing aNavigationLink. Please file a bug.

解決策ググっても全然出てこなかったので、かなり解消に時間がかかりました。。
備忘として雑に残します。

ちなみに本バグは数々のロジックのバグを総称して上記のようなアラートを出しています。
あくまで参考程度に見ていただければ幸いです。

解決策

結論:NavigationLinkをForEachまたListから出してください。

Before:ForEachの中にNavigationLinkを配置していた。

ForEach(self.Memoes.data){i in
   VStack(alignment: .leading, spacing:5){
      NavigationLink(destination: ReadMemoView(data: self.data),isActive:self.$viewControllerModel.ReadMemoViewPushed) {
      Button(action: {
          self.data = i
          self.viewControllerModel.ReadMemoViewPushed.toggle()
      }) {
           Text("テキスト")
          }
      }
   }
}

After:ForEachの外にNavigationLinkを配置する

NavigationLink(destination: ReadMemoView(data: self.data), isActive: self.$viewControllerModel.ReadMemoViewPushed) {
       EmptyView()
}

ForEach(self.Memoes.data){i in
   VStack(alignment: .leading, spacing:5){
      Button(action: {
          self.data = i
          self.viewControllerModel.ReadMemoViewPushed.toggle()
      }) {
           Text("テキスト")
          }
   }
}

ForEachの中でNavigationLinkを行うと繰り返し処理された「isActive」のどれをアクティブ処理するべきか分からなくなってしまうみたい。

5
2
0

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
5
2