Last active
December 3, 2022 10:48
-
-
Save aliakhtar49/b3ee43965145c622b9ddc4222faf02b0 to your computer and use it in GitHub Desktop.
FirstViewUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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