[iOS] 테이블뷰 만들기 (1)
필그램
·2017. 8. 29. 02:54
먼저 스토리 보드에 TabelView를 그림과 같이 넣는다.
[결과화면]
[소스코드] 설명은 코드내에..
import UIKit
class ViewController: UIViewController, UITableViewDataSource {
//0. 위 UITableViewDataSource 입력
//1. 어레이 입력 - 출력될 내용
let data:[String] = ["Item1", "Item2", "Item3"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
// 2. numberOfRowsInSection - 어레이를 카운팅
// return 5 라고하면 5개만 리스트 된다.
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return data.count
}
//3.cellForRowAt - 셀에 나올 내용 선택
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
//4.dequeueReusableCell 입력후, 스토리보드에서 "cell" 입력(맨위 이미지 참조)
cell.textLabel?.text = data[indexPath.row]
return cell
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
'프로그래밍 > 모바일: iOS, Java, Android, Swift' 카테고리의 다른 글
[IOS] 테이블뷰 만들기 (4) : 커스텀 테이블 만들기 (0) | 2017.08.31 |
---|---|
[IOS] 테이블뷰 만들기 (3) : 소제목 넣고, 이미지 추가 (0) | 2017.08.31 |
웹뷰 : 파일 로딩, 웹 페이지 로딩 (0) | 2017.08.26 |
[iOS] 이미지 갤러리 간략소스 (0) | 2017.08.19 |
[iOS] segment(세그먼트) 간략소스 (0) | 2017.08.19 |