iOS 개발 학습 노트 2: UItableView(1)
6149 단어 UITableView
1: 기본 ViewController를 제거하고 TableViewController를 드래그합니다.
2: TableViewController라는 이름으로 새 Cocoa Touch Class
3:1국을 2로 정하다
4: 레이블을 드래그하고 TAG를 1로 설정하고 CELL의 ID를 cell로 설정합니다.
관련 코드:
1 override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
2
3 return 1
4 }
5
6 override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
7
8 return 4
9 }
10
11
12 override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
13 let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
14
15 var label=cell.viewWithTag(1) as UILabel
16
17 label.text=" , "
18
19 return cell
20 }
2: TableView1, TableView 드래그
2, 새 Cocoa Touch Class, 이름: My TV
3, 1과 2를 연결하고 Cell을 TableView로 드래그하여 Cell이라고 명명합니다
4, label 드래그, TAG 설정 1
관련 코드:
1 class MyTV: UITableView,UITableViewDataSource {
2
3
4 let data=[" , ","didisswfids","w "]
5
6 required init(coder aDecoder:NSCoder)
7 {
8 super.init(coder: aDecoder)
9 self.dataSource=self
10 }
11
12 func numberOfSectionsInTableView(tableView: UITableView) -> Int {
13 return 1
14 }
15
16
17 func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
18 return 4
19 }
20
21
22
23
24 func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
25
26
27 let cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
28
29 var label=cell.viewWithTag(1) as UILabel
30
31 label.text=data[indexPath.row]
32
33 return cell
34 }
35 }
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
【Swift】UITableView의 Cell은 재사용됨에 따라 이야기이번에는 여러분도 사용한 적이 있을 UITableView의 이야기를 합니다. UITableView의 셀은 메모리 관계로 재사용됩니다. 그러므로 생각한 대로의 거동이 되어 주지 않는 것이 자주 있습니다. 처음 10개의...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.