LoginSignup
7
3

More than 3 years have passed since last update.

[SwiftUI]NavigationLinkのアクセサリを非表示にするには

Posted at

SwiftUIでは、画面遷移の方法としてNavigationLinkと呼ばれる機能が存在します。
これは、遷移後のViewと表示するViewを指定することでpush遷移を提供するviewです。
NavigationLinkは以下のように、Listの中で使うこともできます。


struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                Text("cat")
                Text("dog")
                NavigationLink(destination: Text("detail")) {
                    Text("fox")
                }
            }
        }
    }
}

しかし、Listの中でNavigationLinkを利用すると自動的に矢印のアクセサリ(UIKitで言うUITableViewCell.AccessoryType.detailDisclosureButton)が表示されます。

スクリーンショット 2019-10-12 22.29.50.png

これを非表示にするには、以下のようにStackの中でNavigationLinkと表示Viewを入れてNavigationLinkではEmptyViewを返すようにします。


struct ContentView: View {
    var body: some View {
        NavigationView {
            List {
                Text("cat")
                Text("dog")
                HStack {
                    Text("fox")
                    NavigationLink(destination: Text("detail")) {
                        EmptyView()
                    }
                }
            }
        }
    }
}

レイアウトによってはVStackとHStackを使い分ける必要があるかと思います。

7
3
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
7
3