2017-04-05 2 views
0

내 ViewController에서 설정 한 UILabel을 업데이트하려고합니다. 이 업데이트는 다른 클래스 인 collectionView의 셀을 눌러 온 것입니다. 레이블은 값을 상속하지만 그래픽으로 업데이트되지 않습니다. 셀을 누르면 뷰 컨트롤러의 새 인스턴스가 만들어지고 현재 셀을 업데이트하지 않기 때문에 이것이 의심 스럽습니다.UILabel이 업데이트되지 않지만 값을 상속받습니다.

현재 인스턴스의 UI 라벨을 업데이트하려면 어떻게해야합니까?

의 ViewController :

import UIKit 
import CoreData 

class mainHomeController: UICollectionViewController, UICollectionViewDelegateFlowLayout { 

    override func viewDidLoad() { 
     super.viewDidLoad() 


     setupBasketBar() 

    } 

    let totNumber: UILabel = { 
     let label = UILabel() 
     label.text = "0" 
     label.numberOfLines = 2 
     return label 
    }() 

    func updateBarText() { 
     totNumber.text = "Update" 
    } 

    func setupBasketBar() { 

     self.view.addSubview(totNumber) 
     totNumber.translatesAutoresizingMaskIntoConstraints = false 
     totNumber.leadingAnchor.constraint(equalTo: view.leadingAnchor,constant: 330).isActive = true 
     totNumber.trailingAnchor.constraint(equalTo: view.trailingAnchor).isActive = true 
     totNumber.bottomAnchor.constraint(equalTo: view.bottomAnchor,constant: 0).isActive = true 
     totNumber.heightAnchor.constraint(equalTo: view.heightAnchor,multiplier: 5).isActive = true 


    } 

} 

작업을 트리거하는 기능 (collectionView 클래스) :

답변

0

당신이 mainHomeControllercollection​View:​did​Select​Item​At​Index​Path:​을 구현했습니다 가정

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 


    mainHomeController().updateBarText() 

}, 당신를 대체 할 수 있습니다.은 updateBarText()입니다.

관련 문제