у меня есть представление коллекции, которая содержит вид и изображение кнопки в каждой клетке, где я нажимаю на ImageView didSelectItemAtIndexPath вызывается, когда нажмите на кнопку он не вызываетdidSelectItemAtIndexPath в не вызвал быстрое
здесь есть код
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(PhotoBrowserCellIdentifier, forIndexPath: indexPath) as! PhotoBrowserCollectionViewCell
let sharedImageCache = FICImageCache.sharedImageCache()
cell.imageView.image = nil
let button = UIButton.buttonWithType(UIButtonType.System) as! UIButton
button.frame = CGRectMake(90, 90, 15, 15)
button.backgroundColor = UIColor.greenColor()
//cell.contentView.addSubview(button)
let photo = photos[indexPath.row] as PhotoInfo
if (cell.photoInfo != photo) {
sharedImageCache.cancelImageRetrievalForEntity(cell.photoInfo, withFormatName: formatName)
cell.photoInfo = photo
// cell.contentView.addSubview(button)
}
sharedImageCache.retrieveImageForEntity(photo, withFormatName: formatName, completionBlock: {
(photoInfo, _, image) -> Void in
if (photoInfo as! PhotoInfo) == cell.photoInfo {
// cell.imageView.image = image
var imgView = UIImageView(image:image!)
imgView.frame = CGRectMake(0,0,cell.frame.size.width, cell.frame.size.height);
cell.contentView.addSubview(imgView)
cell.contentView.addSubview(button)
}
})
return cell
}
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let photoInfo = photosVideo[indexPath.row]
var url = photoInfo.sourceImageURL
button.addTarget(self, action: "showNotice", forControlEvents: UIControlEvents.TouchUpInside)
performSegueWithIdentifier("show photo", sender: ["photoInfo": photoInfo])
println("hello")
}
'button.addTarget (self, action:" showNotice ", forControlEvents: UIControlEvents.TouchUpInside)' Создаете ли вы функцию showNotice? 'FUNC showNotice (отправитель: UIButton) { Println ("BUTTON ЗДЕСЬ") } ' – Maybe1
да я создал –
Почему Вы добавляете цель в кнопке в didSelectItemAtIndexPath? Вам нужно создать действие, когда вы создаете кнопку в cellForItemAtIndexPath, и (я действительно не уверен здесь, поскольку я не уверен, что вы хотите сделать), но я считаю, что вам не нужен didSelectItemAtIndexPath, поскольку что-то должно произойти, когда вы касаетесь кнопка, а не вид – Icaro