Swift5에서 TableView를 사용하는 방법
소개
이번에는 TableView를 사용합니다. ※ 끝 접어 써 버립니다.
"Xib"를 사용하여 사용자 정의 셀을 만들 수도 있지만, 먼저 간단한 스토리 보드의 "Table View cell"로 빨리 구현하고 싶습니다.
환경
Xocde10.2
swift5
구현
코드
먼저 코드를 작성합니다.
test.swiftimport UIKit
class TestPage: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
//cellに表示するデータ
let testList = ["Test1", "Test2", "Test3"]
override func viewDidLoad() {
super.viewDidLoad()
}
//セルの数を指定
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return testList.count
}
//セルに値を設定
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// セルを取得する
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
// セルに表示する値を設定する
cell.textLabel!.text = testList[indexPath.row]
return cell
}
}
스토리보드를 만지다
라이브러리에서 Table View, Table View cell을 배치하려는 화면에 삽입합니다.

아래와 같이 됩니다.

show the Attributes inspector에서 Identifier에 셀을 입력합니다.

끝에
이번에는 Table View의 간단한 사용법을 이야기했습니다.
자주 보는 일반적인 TableView는 이것으로 괜찮습니다만, UI/UX를 신경쓰는 레이아웃등에서는 역시 「Xib」를 사용한 커스텀 셀이 추천입니다. 우선은 기본으로부터 이런 것으로 간단하게 구현할 수 있다는 것을 알고 스텝 업으로 커스텀 셀을 자작하는 것도 좋다고 생각합니다.
Reference
이 문제에 관하여(Swift5에서 TableView를 사용하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kaneko77/items/421769210c43d4abbbd9
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
Xocde10.2
swift5
구현
코드
먼저 코드를 작성합니다.
test.swiftimport UIKit
class TestPage: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
//cellに表示するデータ
let testList = ["Test1", "Test2", "Test3"]
override func viewDidLoad() {
super.viewDidLoad()
}
//セルの数を指定
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return testList.count
}
//セルに値を設定
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// セルを取得する
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
// セルに表示する値を設定する
cell.textLabel!.text = testList[indexPath.row]
return cell
}
}
스토리보드를 만지다
라이브러리에서 Table View, Table View cell을 배치하려는 화면에 삽입합니다.

아래와 같이 됩니다.

show the Attributes inspector에서 Identifier에 셀을 입력합니다.

끝에
이번에는 Table View의 간단한 사용법을 이야기했습니다.
자주 보는 일반적인 TableView는 이것으로 괜찮습니다만, UI/UX를 신경쓰는 레이아웃등에서는 역시 「Xib」를 사용한 커스텀 셀이 추천입니다. 우선은 기본으로부터 이런 것으로 간단하게 구현할 수 있다는 것을 알고 스텝 업으로 커스텀 셀을 자작하는 것도 좋다고 생각합니다.
Reference
이 문제에 관하여(Swift5에서 TableView를 사용하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/kaneko77/items/421769210c43d4abbbd9
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
import UIKit
class TestPage: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var tableView: UITableView!
//cellに表示するデータ
let testList = ["Test1", "Test2", "Test3"]
override func viewDidLoad() {
super.viewDidLoad()
}
//セルの数を指定
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return testList.count
}
//セルに値を設定
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
// セルを取得する
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
// セルに表示する値を設定する
cell.textLabel!.text = testList[indexPath.row]
return cell
}
}
이번에는 Table View의 간단한 사용법을 이야기했습니다.
자주 보는 일반적인 TableView는 이것으로 괜찮습니다만, UI/UX를 신경쓰는 레이아웃등에서는 역시 「Xib」를 사용한 커스텀 셀이 추천입니다. 우선은 기본으로부터 이런 것으로 간단하게 구현할 수 있다는 것을 알고 스텝 업으로 커스텀 셀을 자작하는 것도 좋다고 생각합니다.
Reference
이 문제에 관하여(Swift5에서 TableView를 사용하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/kaneko77/items/421769210c43d4abbbd9텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)