はじめに
前回からの続きでSwiftUIのチュートリアル入門になります。
もと記事サイト
![](https://tatsunori-morita.com/wp-content/uploads/cocoon-resources/blog-card-cache/8c8f6e4facf0020077138aac5f26c7f0.jpg)
Building lists and navigation | Apple Developer Documentation
With the basic landmark detail view set up, you need to provide a way for users to see the full list of landmarks, and t...
Step0
このセクションでは、前回までに作成したLandmarkのセルをリスト表示できるようにします。
Step1
LandmarkList.swift
ファイルを新規作成します。
![](https://tatsunori-morita.com/wp-content/uploads/2021/02/image-4.png)
Step2
初期表示されているText
を削除して、LandmarkRow
をList
で囲んで記載します。
import SwiftUI
struct LandmarkList: View {
var body: some View {
List {
LandmarkRow(landmark: landmarks[0])
LandmarkRow(landmark: landmarks[1])
}
}
}
struct LandmarkList_Previews: PreviewProvider {
static var previews: some View {
LandmarkList()
}
}
リストが簡単に表示されましたね!
![](https://tatsunori-morita.com/wp-content/uploads/2021/02/image-5.png)
まとめ
セルとなるViewを作成し、List
で囲んで表示するだけで、UITableViewと同様のリスト表示ができるのはとても簡単ですね。
コメント