我在视图中有两个容器.顶部有一个集合视图.我想从下面的容器中点击按钮时从按钮更新我的集合视图.我的按钮也改变了我的集合视图使用的数组的值.
我以为didSet会做这个工作,但不幸的是没有用.
最佳:
class TopViewController: UIViewController, UICollectionViewDataSource, UICollectionViewDelegate {
@IBOutlet weak var favoritesCV: UICollectionView!
var myFavorites = [] {
didSet {
self.favoritesCV.reloadData()
}
}
override func viewDidAppear(animated: Bool) {
myFavorites = favoritesInstance.favoritesArray
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return myFavorites.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell : FavoritesCollectionViewCell = collectionView.dequeueReusableCellWithReuseIdentifier("Cell", forIndexPath: indexPath) as! FavoritesCollectionViewCell
var myPath = myFavorites[indexPath.row] as! String
cell.myImage.image = UIImage(named: myPath)
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
底部:
class …
Run Code Online (Sandbox Code Playgroud) 我有两个控制器.第一个有一个带有书签按钮项目的导航栏,我按下它来显示我的第二个控制器,里面有一个tableview.
此链接的示例项目:http://www.koraybirand.co.uk/download/xcode/PopTest.zip
我希望能够选择一个单元格然后关闭弹出视图.
另一个奇怪的行为是,第一个单元格显示一个警报视图控制器,它可以在iPhone上正常工作,但在iPad上,弹出窗口会突然调整到alerviewcontroller的大小.
这是我的主视图控制器:
class ViewController: UIViewController, UIPopoverPresentationControllerDelegate {
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.
}
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "popoverSegue" {
let popoverViewController = segue.destinationViewController as! UIViewController
popoverViewController.modalPresentationStyle = UIModalPresentationStyle.Popover
popoverViewController.popoverPresentationController!.delegate = self
}
}
func adaptivePresentationStyleForPresentationController(controller: UIPresentationController) -> UIModalPresentationStyle {
return UIModalPresentationStyle.None
}
} …
Run Code Online (Sandbox Code Playgroud)