使用UICollectionView

import UIKitclass ViewController: UIViewController,UICollectionViewDataSource,UICollectionViewDelegate {@IBOutlet weak var textField: UITextField!@IBOutlet weak var mCollectionView: UICollectionView!var cell:CountCollectionViewCell? = nilvar mUtil = Util()//当控制器的视图类加载完成时调用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.}//cell个数func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int{return 15;}//相当于android中的getviewfunc collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell{cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as CountCollectionViewCellcell!.setViewLabel(indexPath)return cell!}//具体点击的哪个cellfunc collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {textField.text = mUtil.getCharacter(indexPath)}}最重要的就是相当于android中的getview方法,,我们把我们的cell回调给上层得以在界面中显示出来,接下来看看效果

于是,月醉了,夜醉了,我也醉了。

使用UICollectionView

相关文章:

你感兴趣的文章:

标签云: