Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UICollectionView单元重用性问题-swift_Ios_Iphone_Swift_Uicollectionview_Uicollectionviewcell - Fatal编程技术网

Ios UICollectionView单元重用性问题-swift

Ios UICollectionView单元重用性问题-swift,ios,iphone,swift,uicollectionview,uicollectionviewcell,Ios,Iphone,Swift,Uicollectionview,Uicollectionviewcell,我正在为我的应用程序使用集合视图。我面临着电池的可重用性问题。我正在为UICollectionViewCell参加一个单独的课程,我已经绑定了插座。请参阅下面的代码片段: class ViewController: UIViewController, UICollectionViewDelegate, UICollectionViewDataSource { @IBOutlet weak var collectionview: UICollectionView! // An array to

我正在为我的应用程序使用集合视图。我面临着电池的可重用性问题。我正在为UICollectionViewCell参加一个单独的课程,我已经绑定了插座。请参阅下面的代码片段:

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
}

添加您的
CollectionViewCell1
类,并通过打印检查
cell
变量的值。您的代码没有解释问题。您可以发布collectionViewCell类并在运行项目时说明问题吗…@Joe这是我完整的代码片段。我已经编辑了问题中的代码。当我运行应用程序时,每个单元格都有一个来自数组“category”的标签。当我上下滚动时,我可以看到标签文本彼此重叠。所以你能帮我解决这个问题吗?你的代码看起来不错,但我不确定你的其他类。从您的代码中,您只需使用webView将URL链接传递到您的2ndVC.r u以加载此URL?。您的代码没有解释您的问题。请告诉我您面临的问题…但从上面的代码中,您无法将数据传递到2ndVC。因为您尚未在mainVC和2ndVC上分配数据字符串,如var strUrl=string()。非常感谢。但是我已经使用了这个重写func prepareforuse()->Void{imageopenview.image=nil titlelabel.text=nil}不,它没有。Plz帮助