Files
2021-04-23 09:51:10 +02:00

120 lines
4.3 KiB
Swift
Executable File

//
// Copyright (c) 2021 Related Code - https://relatedcode.com
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
import UIKit
//-----------------------------------------------------------------------------------------------------------------------------------------------
class Channels1View: UIViewController {
@IBOutlet var tableView: UITableView!
private var channels: [[String: Any]] = []
//-------------------------------------------------------------------------------------------------------------------------------------------
override func viewDidLoad() {
super.viewDidLoad()
title = "Channels"
navigationItem.rightBarButtonItem = UIBarButtonItem(image: UIImage(systemName: "slider.horizontal.3"), style: .done, target: self, action: #selector(actionFilter))
tableView.register(UINib(nibName: "Channel1Cell", bundle: nil), forCellReuseIdentifier: "Channel1Cell")
tableView.tableFooterView = UIView()
loadData()
}
// MARK: - Data methods
//-------------------------------------------------------------------------------------------------------------------------------------------
func loadData() {
channels.removeAll()
var dict1: [String: Any] = [:]
dict1["name"] = "AC/DC Official"
dict1["isVerified"] = true
dict1["subscribers"] = "65M subs"
dict1["videos"] = "3.9K videos"
dict1["isSubscribed"] = false
channels.append(dict1)
var dict2: [String: Any] = [:]
dict2["name"] = "The Weeknd"
dict2["isVerified"] = false
dict2["subscribers"] = "65M subs"
dict2["videos"] = "3.9K videos"
dict2["isSubscribed"] = true
channels.append(dict2)
channels.append(dict1)
channels.append(dict2)
channels.append(dict1)
channels.append(dict2)
channels.append(dict1)
channels.append(dict2)
refreshTableView()
}
// MARK: - User actions
//-------------------------------------------------------------------------------------------------------------------------------------------
@objc func actionFilter() {
print(#function)
}
// MARK: - Refresh methods
//-------------------------------------------------------------------------------------------------------------------------------------------
func refreshTableView() {
tableView.reloadData()
}
}
// MARK: - UITableViewDataSource
//-----------------------------------------------------------------------------------------------------------------------------------------------
extension Channels1View: UITableViewDataSource {
//-------------------------------------------------------------------------------------------------------------------------------------------
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return channels.count
}
//-------------------------------------------------------------------------------------------------------------------------------------------
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return UITableView.automaticDimension
}
//-------------------------------------------------------------------------------------------------------------------------------------------
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "Channel1Cell", for: indexPath) as! Channel1Cell
cell.bindData(index: indexPath.item, data: channels[indexPath.row])
return cell
}
}
// MARK: - UITableViewDelegate
//-----------------------------------------------------------------------------------------------------------------------------------------------
extension Channels1View: UITableViewDelegate {
//-------------------------------------------------------------------------------------------------------------------------------------------
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("didSelectItemAt \(indexPath.row)")
tableView.deselectRow(at: indexPath, animated: true)
}
}