【发布时间】:2015-10-05 00:45:10
【问题描述】:
我正在尝试从集合视图单元格中打印 cell.image.text。
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: indexPath) as! CollectionViewCell
let post = self.arrayOfDetails[indexPath.row]
cell.currentUserLabel.text = post.username
cell.imageText.text = post.text
cell.uploadedTimeLabel.text = post.CreatedAt.timeAgo
cell.imageView.setImageWithUrl(NSURL(string: post.image)!, placeHolderImage: UIImage(named: "Placeholder"))
return cell
}
ArrayOfDetails:
var arrayOfDetails = [Details]()
详情:
struct Details {
var username:String!
var text:String!
var CreatedAt:NSDate!
var image:String!
init(username:String,text:String,CreatedAt:NSDate,image:String){
self.username = username
self.text = text
self.CreatedAt = CreatedAt
self.image = image
}
}
这就像一个Instagram应用程序,所以有多个带有照片和照片文字的单元格,我有一个按钮,当按下按钮时,它想要println(cell.image.text)。我该怎么做?
我试过了:
@IBAction func printButton(sender: AnyObject) {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("cell", forIndexPath: nil) as! CollectionViewCell
println(cell.imageText.text)
}
但它没有显示任何文字。
【问题讨论】:
-
每个单元格内都有一个打印按钮?
-
是的,一个标志按钮。我想在
didDeselectItemAtIndexPath中检测何时按下标志按钮。如何做到这一点? -
为什么特别是在 didDeselectItemAtIndexPath 中?您可以将您的单元格子类化,给它一个 uibutton 属性并在您的 collectionviewcustomcell.m 中设置它的行为。
-
怎么样? (迅速)
-
:D 我刚才已经做出了回应,但它在目标 C 中:stackoverflow.com/questions/23801418/…。你能理解还是我应该解释一下?
标签: ios swift uicollectionview uicollectionviewcell