Swift 프록시 전송 및 클로즈업 전송

3183 단어
A-B 그리고 B는 값을 A에 전달합니다. A는 CollectionView B가 A의 개수를 바꾸는oc에서 프로토콜에 @objc A 코드를 추가할 수 없으면 import UIKit class ViewController: UIViewController, UICollection View Delegate, UICollection View DataSource,SecondVCDelegate { @IBOutlet weak var collectionView : UICollectionView? var count = 5; override func viewDidLoad() { super.viewDidLoad()//Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
    return count;
}

func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
    let cell = collectionView.dequeueReusableCellWithReuseIdentifier("MyCollectionViewCell", forIndexPath: indexPath)
    
    return cell;
}


func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat{
    return 5;
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat{
    return 5;
}

func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize{ return CGSizeMake((UIScreen.mainScreen().bounds.size.width-15)/3, (UIScreen.mainScreen().bounds.size.width-15)/3); }
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
    let secondVC = SecondViewController()

//secondVC.delegate = self secondVC.myValue = {(count)->Void in self.count = count self.collectionView?.reloadData() } let nav_ctrl = UINavigationController.init(rootViewController: secondVC) self.presentViewController(nav_ctrl, animated: true) {
    }
}

func updateCount() {
    count = 20
    self.collectionView?.reloadData()
}

}
B 코드:
import UIKit protocol SecondVCDelegate { func updateCount(); }
typealias SendValue = (count:Int)->Void
Class SecondViewController: UIViewControler {var delegate: SecondVavavavavavavavave: SendVavale: var myValue: var my Valegate::var my Value: SendValue: SendValue: Valuelue? overrie func vie func view DidLoad() {슈퍼 view vidLoad() let backBtn Btn = let backBtn = UIBtn = UIBtton.initit: initton. init(프레임(frame: framame::CCGMMMMMMMMforState:.Normal) backBtn.addTarget(self, action: #selector(SecondViewController.back), forControlEvents: .TouchUpInside) let backItem = UIBarButtonItem.init(customView: backBtn)
    self.navigationItem.leftBarButtonItem = backItem
}

func back() {
    self.dismissViewControllerAnimated(true) {
        self.myValue!(count: 6)

//self.delegate?.updateCount() } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning()//Dispose of any resources that can be recreated. }
}

좋은 웹페이지 즐겨찾기