[ad_1]
In my primary View Controller I’ve a UITableViewCell that generates customized cells from a UITableViewCell class.
I am making an attempt to go particular knowledge from a button (variety of likes) that’s in my second View Controller (NftList ViewController) to my primary View controller (my primary VC) and current the worth on a TableViewCell that generates cell from the opposite UITableViewCell (AssetTableViewCell). Unsure the right way to go it into the ViewController.swift . It perhaps want so as to add that worth to an array into the View Controller file for helpthis course of work I do not know.
Any helps ?
CODE:
class AssetTableViewCell: UITableViewCell {
@IBOutlet var nameLabel : UILabel!
@IBOutlet var iconView : UIImageView!
@IBOutlet var likesLabel: UILabel!
var nfts:Nft?
override func awakeFromNib() {
tremendous.awakeFromNib()
nameLabel.layer.cornerRadius = nameLabel.body.peak/2
likesLabel.layer.cornerRadius = likesLabel.body.peak/2
}
override func setSelected(_ chosen: Bool, animated: Bool) {
tremendous.setSelected(chosen, animated: animated)
}
}
ViewController:
class ViewController: UIViewController , UITableViewDelegate , UITableViewDataSource , LikesDelegate , testDelegate {
var numlikes: Int = 0
func countLks() {
let lks = "((numlikes))"
print(lks)
}
@IBOutlet weak var tableView: UITableView!
public var likes:[Int] = []
override func viewDidLoad() {
tremendous.viewDidLoad()
let nib = UINib(nibName: "AssetTableViewCell", bundle: nil)
tableView.register(nib, forCellReuseIdentifier: "AssetTableViewCell")
tableView.dataSource = self //technique to generate cells,header and footer earlier than they're displaying
tableView.delegate = self //technique to supply details about these cells, header and footer ....
downloadJSON {
self.tableView.reloadData()
print("success")
}
}
var nfts: [Nft] = []
var icons: [Icon] = []
//orizo ton arithmo ton rows tou desk
func tableView(_ tableView: UITableView, numberOfRowsInSection part : Int) ->Int {
return nfts.rely
}
//gemizo ta rows tou desk
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "AssetTableViewCell",
for: indexPath) as! AssetTableViewCell
let nft = nfts[indexPath.row]
cell.nameLabel?.textual content = nft.title
cell.nameLabel.layer.cornerRadius = cell.nameLabel.body.peak/2
cell.likesLabel?.textual content = "((countLikes()))"
let imgUrl = (nft.image_url)
print(imgUrl)
cell.iconView.downloaded(from: imgUrl)
cell.iconView.layer.cornerRadius = cell.iconView.body.peak/2
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
performSegue(withIdentifier: "showDetails", sender: self)
}
override func put together(for segue: UIStoryboardSegue, sender: Any?) {
if let vacation spot = segue.vacation spot as? NftListViewController {
vacation spot.nft = nfts[tableView.indexPathForSelectedRow!.row]
}
}
func countLikes(){
print("like")
}
func downloadJSON(accomplished: @escaping () -> ()) {
let url = URL(string: "https://public.arx.web/~chris2/nfts.json")
URLSession.shared.dataTask(with: url!) { knowledge, response, err in
if err == nil {
do {
self.nfts = strive JSONDecoder().decode([Nft].self, from: knowledge!)
DispatchQueue.primary.async {
accomplished()
}
}
catch {
print("error fetching knowledge from api")
}
}
}.resume()
}
}
non-public var viewModels = [NftListViewController]()
NftListViewController :
protocol LikesDelegate: AnyObject {
var numlikes:Int{get set}
func countLks()
}
protocol testDelegate{
func sendBackTheLikess(int:Int)
}
protocol CounterProtocol{
var rely:Int{get set}
}
extension UIImageView {
func downloaded(from url: URL, contentMode mode: ContentMode = .scaleAspectFit) {
contentMode = mode
URLSession.shared.dataTask(with: url) { knowledge, response, error in
guard
let httpURLResponse = response as? HTTPURLResponse, httpURLResponse.statusCode == 200,
let mimeType = response?.mimeType, mimeType.hasPrefix("picture"),
let knowledge = knowledge, error == nil,
let picture = UIImage(knowledge: knowledge)
else { return }
DispatchQueue.primary.async() { [weak self] in
self?.picture = picture
}
}.resume()
}
func downloaded(from hyperlink: String, contentMode mode: ContentMode = .scaleAspectFit) {
guard let url = URL(string: hyperlink) else { return }
downloaded(from: url, contentMode: mode)
}
}
class NftListViewController: UIViewController , LikesDelegate ,CounterProtocol, testDelegate {
func sendBackTheLikess(int: Int) {
<#code#>
}
//weak var delegate: LikesDelegate?
static let identifier = "NftListViewController"
var numlikes: Int = 0
var rely:Int = 0
var press = false
@IBOutlet weak var lbl_Id: UILabel!
@IBOutlet weak var img_View: UIImageView!
@IBOutlet weak var lbl_Name: UILabel!
@IBOutlet var likeButton: UIButton!
func countLks() {
rely = rely + 1
print(rely)
}
var delegate : testDelegate?
@IBAction func sendBackTheLikess(_ sender: UIButton) {
rely = rely + 1
print("h timi tou rely einai : (rely)")
delegate?.sendBackTheLikess(int: rely)
}
@IBAction func didTapButton(_ sender: Any) {
press = true
countLikes()
}
@IBAction func popupTapped(_ sender: UIButton) {
displayPopUp()
}
var nft: Nft?
var icon: Icon?
static let numberFormatter : NumberFormatter = {
let formatter = NumberFormatter()
formatter.locale = .present
formatter.allowsFloats = true
formatter.numberStyle = NumberFormatter.Type.forex
formatter.formatterBehavior = .default
return formatter
}()
override func viewDidLoad() {
tremendous.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(didGetNotification(_:)), title: Notification.Title("title"), object: nil)
lbl_Name.textual content = nft?.title
lbl_Id.textual content = "((nft?.id)!)"
print(rely)
// likeButton.addTarget(self, motion: #selector(countLikes), for: .touchUpInside)
let imgUrl = (nft?.image_url)!
print(imgUrl)
img_View.downloaded(from: imgUrl)
}
@objc func didGetNotification(_ notification: Notification){
let title = notification.object as! String?
lbl_Name.textual content = title
}
@objc non-public func countLikes(){
//delegate?.countLks()
}
func displayPopUp () {
let storyBoard = UIStoryboard(title: "Fundamental", bundle: nil)
let vc = storyBoard.instantiateViewController(withIdentifier: "PopUpViewController") as! PopUpViewController
vc.nft = nft
self.current(vc, animated: true, completion: nil)
self.navigationController?.pushViewController(vc, animated: true)
}
override func put together(for segue: UIStoryboardSegue, sender: Any?) {
displayPopUp()
}
}
[ad_2]
