我正在寻找创建三个tableview文本域单元格,并且我试图找出创建它的机制。到目前为止,我已经创建了一个公共类,它包含我的文本域和一个配置函数,将值传递给出口属性,但是我很难知道如何将这些行传递给tableview,特别是当它涉及重用标识符时。我该怎么做到这一点?
UserRegistrationTableViewCells.swift:
import Foundation
public class UserRegistrationTableViewCells: UITableViewCell {
@IBOutlet var usernameTextField: UITextField!
@IBOutlet var emailTextField: UITextField!
@IBOutlet var passwordTextField: UITextField!
public func configure(#text: String?, placeholder: String){
usernameTextField.text = text
usernameTextField.placeholder = placeholder
usernameTextField.accessibilityValue = text
usernameTextField.accessibilityLabel = placeholder
emailTextField.text = text
emailTextField.placeholder = placeholder
emailTextField.accessibilityValue = text
emailTextField.accessibilityLabel = placeholder
passwordTextField.text = text
passwordTextField.placeholder = placeholder
passwordTextField.accessibilityValue = text
passwordTextField.accessibilityLabel = placeholder
}
UserRegistrationViewController.swift:
import UIKit
class UserRegistrationViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var registrationTableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("usernameTextField") as UserRegistrationTableViewCells
return UITableViewCell()
}