ios - UICollectionView 单元可重用性问题 - swift

标签 ios iphone swift uicollectionview uicollectionviewcell

VC code Overlapping text label issue

我正在为我的应用程序使用 Collection View。我正面临单元可重用性问题。我正在为 UICollectionViewCell 上一个单独的类(class),我已经绑定(bind)了网点。请引用下面的代码片段:

class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource {

@IBOutlet weak var collectionview: UICollectionView!

// An array to create desired number of cells in the home screen collection view 

let category = ["About Us", "Program Structure", "Courses", "Linkedin" , "Latest News", "Contact Us","Facebook", "Twitter", "Youtube", "Student Portal", "Alumni", "Faculty", "Career Center", "Free Software", "Apply Now", "FAQ"]

let imagearray = [UIImage (named: "Entypo_d83d(1)_512"), UIImage (named: "Entypo_d83d(0)_1024-6"), UIImage (named: "Entypo_d83d(0)_1024"), UIImage (named: "Entypo_f318(0)_1024"), UIImage (named: "Entypo_e776(0)_1024"), UIImage (named: "Entypo_d83d(0)_1024-2"),UIImage (named: "Entypo_f30c(0)_1024"), UIImage (named: "Entypo_f309(0)_1024"), UIImage (named: "Entypo_d83c(0)_1024-1"), UIImage (named: "Entypo_e78e(0)_1024"), UIImage (named: "Entypo_e722(0)_1024"), UIImage (named: "Entypo_d83d(0)_1024-1"), UIImage (named: "Entypo_d83d(0)_1024-3"), UIImage (named: "Entypo_d83d(0)_1024-4"), UIImage (named: "Entypo_e789(0)_1024"), UIImage (named: "Entypo_d83d(0)_1024-5")]

let webarray = ["http://ed.fullerton.edu/msidt/about-our-department/", "http://ed.fullerton.edu/msidt/future-students/program-structure/", "http://ed.fullerton.edu/msidt/future-students/courses/", "https://www.linkedin.com/in/msidt-csuf-9ab982119", "http://ed.fullerton.edu/msidt/category/news/", "http://ed.fullerton.edu/msidt/about-our-department/contact-information/", "https://www.facebook.com/MSIDTFullerton/", "https://twitter.com/msidt", "https://www.youtube.com/watch?v=hAu_Ef22gvA", "https://shibboleth.fullerton.edu/idp/profile/SAML2/Redirect/SSO?execution=e1s1", "http://ed.fullerton.edu/msidt/alumni/", "http://ed.fullerton.edu/msidt/faculty/", "http://www.fullerton.edu/career/", "http://www.fullerton.edu/it/students/software/", "http://ed.fullerton.edu/msidt/apply-now/", "http://ed.fullerton.edu/msidt/future-students/faq/"]

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.     
}

//to set the number of cells

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

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

    let cell = collectionview.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell1

    cell.imageopenview.image = self.imagearray[indexPath.item]

    cell.titlelabel .text = self.category[indexPath.item]

    return cell   
}

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


    let secondViewController = self.storyboard!.instantiateViewControllerWithIdentifier("newVC") as! NewViewController
    secondViewController.strUrl = webarray[indexPath.item]
    self.navigationController!.pushViewController(secondViewController, animated: true)

 }
}

我非常需要帮助。请给我解决方案。提前致谢。

最佳答案

CollectionViewCell1 类中试试这个

override func prepareForReuse() {
    titlelabel.text = nil
}

关于ios - UICollectionView 单元可重用性问题 - swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40325637/

相关文章:

ios - 提高GKAgent的速度

iphone - 关于在 iOS 和 Android 上开发多人游戏的建议?

ios - 当 DatePicker 隐藏单元格时移动 ScrollView

iphone - 推式转场场景有效,模态转场场景不行?

ios - 应用程序委托(delegate)的 Swift Xcode 7 错误

ios - 将控制命令发送到 UIWebView 以进行在线游戏 - Swift

ios - 如何在 Swift 中按名称/标识符从相机胶卷中获取图像

ios - xcode - 当我更改 View 时标签更改值

iphone - UIButtons 不启用其他按钮

iphone - 在后台调用函数和在线程中调用函数的区别