2016-11-21 4 views
0

This is how it looksuicollectionviewcell Etiketten falsch ausgerichtet nach dem Neuladen

ich folgenden Code versucht, auf dem Bildschirm einfache Sammlung Ansicht zu machen. Aber Subviews in Contentview nicht richtig Algin

Ich bin in Swift 2.3 mit Xcode 7.3.1 codieren Warum ist das passiert?

Hier ist der Code

import Foundation 
class CustomerOverdueViewController : BaseViewController , UICollectionViewDelegateFlowLayout { 

    @IBOutlet weak var collectionView: UICollectionView! 
    @IBOutlet weak var tableView: UITableView! 

    @IBOutlet weak var lblTotalOverdue: UILabel! 
    @IBOutlet weak var lblInvestedFunds: UILabel! 

    @IBOutlet weak var segmentedControl: UISegmentedControl! 

    var rangeArray = NSArray() 
    var selectedOverdueIndex = 0 
    var selectedColor = UIColor() 

    override func viewDidLoad() { 
     super.viewDidLoad() 

     self.title = "Customer Overdue" 

    } 


    @IBAction func segValueChanged(sender: UISegmentedControl) { 

    } 

    func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int { 
     return 1 
    } 

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

    func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell { 

     let reuseIdentifier = String("CustomerOverdueCollectionViewCell") 
     let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as! CustomerOverdueCollectionViewCell 
     return cell 
    } 

    func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath){ 
    } 


    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize 
    { 
     return CGSize(width: collectionView.frame.size.width/2 - 10, height: collectionView.frame.size.height/3 - 10) 
    } 

    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, insetForSectionAtIndex section: Int) -> UIEdgeInsets 
    { 
     return UIEdgeInsets(top: 5, left: 5, bottom: 0, right: 5) 
    } 
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAtIndex section: Int) -> CGFloat 
    { 
     return 10.0 
    } 
    func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAtIndex section: Int) -> CGFloat 
    { 
     return 10.0 
    } 

} 
+0

verwenden Sie Autolayout oder Autoresizing? – Vinodh

+0

Ich benutze Autolayouts – Anik

+0

Ich denke, Sie haben Konflikt in Contraints in collectionview lösen Sie sie werden in der Lage, deirred output.Please Post initial Image, die ordentlich vor dem Reload aussehen – Vinodh

Antwort

1

es, dass die Daten in dem ersten Aufruf scheint verwendet, wenn die Tabelle zuerst (von ViewWillLoad) gezogen wird. Wenn Sie die Daten jedoch aktualisieren, werden die Einschränkungen nicht neu berechnet.

Normalerweise wird dies über setNeedsLayout getan und/oder layoutIfNeeded Sie können versuchen:

[view layoutIfNeeded]; 
1

Schließlich ich die Lösung bekam

Aufschalten layoutSubviews in der kundenspezifischen Zell

override func layoutSubviews() { 
    super.layoutSubviews() 
    self.layoutIfNeeded() 
} 

und fügen Sie folgende Zeilen in cellForItemAtIndexpath

cell.setNeedsLayout() 
    cell.layoutIfNeeded() 
Verwandte Themen