Skip to content

Instantly share code, notes, and snippets.

@aliakhtar49
Last active December 3, 2022 10:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aliakhtar49/b3ee43965145c622b9ddc4222faf02b0 to your computer and use it in GitHub Desktop.
Save aliakhtar49/b3ee43965145c622b9ddc4222faf02b0 to your computer and use it in GitHub Desktop.
FirstViewUI
import UIKit
final class FirstViewUI: UIView {
var names =
[
"first",
"seo",
"psum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the in",
"four",
"five",
"six",
"six"
]
fileprivate lazy var tableView: UITableView = {
let tbl = UITableView(frame: .zero, style: .plain)
tbl.separatorStyle = .none
tbl.dataSource = self
tbl.translatesAutoresizingMaskIntoConstraints = false
tbl.register(CustomUITableViewCell.self, forCellReuseIdentifier: CustomUITableViewCell.identifier)
return tbl
}()
override init(
frame: CGRect = .zero
) {
super.init(frame: frame)
setupUIElements()
setupConstraints()
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
fileprivate func setupUIElements() {
addSubview(tableView)
}
fileprivate func setupConstraints() {
tableView.bottomAnchor.constraint(equalTo: bottomAnchor, constant: 0).isActive = true
tableView.leadingAnchor.constraint(equalTo:leadingAnchor, constant: 0).isActive = true
tableView.trailingAnchor.constraint(equalTo: trailingAnchor, constant: 0).isActive = true
tableView.heightAnchor.constraint(equalToConstant: 300).isActive = true
}
}
extension FirstViewUI: UITableViewDataSource {
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return names.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
guard let cell = tableView.dequeueReusableCell(
withIdentifier: CustomUITableViewCell.identifier,
for: indexPath
) as? CustomUITableViewCell else {
fatalError("Error in CustomUITableViewCell Cell")
}
cell.titleLabel.text = names[indexPath.row]
return cell
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment