Cree un archivo XIB:
Archivo -> nuevo Archivo -> ios-> clase cocoa touch -> siguiente

asegúrese de marcar "también crear archivo XIB"
Me gustaría actuar con, tableview
así que elegí la subclaseUITableViewCell
puede elegir como su requerimiento

Diseño de archivo XIB como desee (RestaurantTableViewCell.xib)

Necesitamos tomar la altura de la fila para establecer la altura de cada fila.

¡Ahora! Necesito engañarlos rápidamente. Estoy engañado restaurantPhoto
y restaurantName
ustedes pueden follar a todos ustedes.

Ahora agregando un UITableView

name
El nombre del archivo nib, que no necesita incluir la extensión .nib.
propietario
El objeto que se asignará como el objeto Propietario del archivo de la plumilla.
opciones
Un diccionario que contiene las opciones que se utilizarán al abrir el archivo nib.
primero,
si no define primero, luego tomando todas las vistas ... así que necesita tomar una vista dentro de ese conjunto frist
.
Bundle.main.loadNibNamed("yourUIView", owner: self, options: nil)?.first as! yourUIView
aquí está el código completo del controlador de vista de tabla
import UIKit
class RestaurantTableViewController: UIViewController ,UITableViewDataSource,UITableViewDelegate{
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 numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let restaurantTableviewCell = Bundle.main.loadNibNamed("RestaurantTableViewCell", owner: self, options: nil)?.first as! RestaurantTableViewCell
restaurantTableviewCell.restaurantPhoto.image = UIImage(named: "image1")
restaurantTableviewCell.restaurantName.text = "KFC Chicken"
return restaurantTableviewCell
}
// set row height
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 150
}
}
lo hiciste :)
