iOS
UITableViewController
수색…
소개
테이블 뷰를 관리하는 UITableViewController 컨트롤러 개체입니다. 일부 시나리오의 경우 UITableViewController를 사용하는 것이 좋습니다 (예 : 셀이 많고 UITextfield가있는 경우).
tableviewCellStyle을 기본으로하는 동적 속성이있는 TableView입니다.
override func numberOfSections(in tableView: UITableView) -> Int {
// You need to return minimum one to show the cell inside the tableview
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return the number of rows inside the tableview.
return 3
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath)
// identifier string should be same as what you have entered in the cell Attribute inspector -> identifier (see the image).
// Configure the cell...
cell.textLabel?.text = "Cell \(indexPath.row) :" + "Hello"
//cell have different style Custom, basic, right detail, left detail, subtitle.
//For custom you can use your own objects and constrains, for other styles all
//is ready just select according to your design. (see the image for changing the style)
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// this delegate method will trigger when you click a cell
}
사용자 지정 셀이있는 TableView
사용자 정의 tableview 셀의 경우 UITableViewCell
하위 클래스 인 클래스가 필요합니다.이 클래스는 아래에서 볼 수 있습니다.
class TableViewCell: UITableViewCell {
@IBOutlet weak var lblTitle: UILabel!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
}
귀하의 tableview 대리인
override func numberOfSections(in tableView: UITableView) -> Int {
// You need to return minimum one to show the cell inside the tableview
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// return the number of rows inside the tableview.
return 3
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Cell", for: indexPath) as! TableViewCell
// identifier string should be same as what you have entered in the cell Attribute inspector -> identifier.
// Configure the cell...
cell.lblTitle.text = "Cell \(indexPath.row) :" + "Hello"
return cell
}
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// this delegate method will trigger when you click a cell
}
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow