我正在开发一个应用程序,我在其中实现了编辑模式.UICollectionView我正在尝试实现这样的事情:

当我点击编辑按钮时,相机按钮和眼睛按钮应该隐藏,删除和重命名按钮应该如下所示:

编辑完成后,当我点击"完成"按钮时,删除按钮和重命名按钮应该隐藏,相机按钮和眼睛按钮应该再次出现.我试过了,但它给了我一些奇怪的输出.一切正常,除了这个"编辑"按钮功能.任何人都可以建议我解决这个问题.建议将不胜感激.请提供一些建议.提前致谢.
我有一个带有imageView和collectionView的视图.ImageView位于屏幕左上角,大小(150,250).CollectionView是全屏.collectView的单元格里面有标签.
当单元格靠近imageView时,它的宽度应该更小.当单元格低于imageView时,它应该是全宽的.这也应该在滚动时工作,因此单元格的大小应该动态变化.所以,我需要制作一个自定义布局.我想,"layoutAttributesForElementsInRect:"是一个答案.但是如何使细胞属性在某个矩形中发生变化?还是我正朝着错误的方向前进?先感谢您.

ios uicollectionview uicollectionviewcell uicollectionviewlayout
我UICollectionView在一个部分中显示了很多项目,使用包裹多行UICollectionViewFlowLayout.
是否有一种简单的方法来确定给定的实际行和列UICollectionViewCell?
在下面的示例图中,我正在寻找行和列:

这只是一个例子 - 在实际的应用程序中,我不知道有多少列.我知道我可以通过知道单元格宽度,集合视图插入和间距来计算,但我希望有另一种方法可以给我答案.
ios uicollectionview uicollectionviewcell uicollectionviewlayout
如何在UICollectionView的一部分中设置单元格间距?UICollectionView有一个属性minimumInteritemSpacing,我需要设置1.0仍然无法正常工作.我实现了委托方法.
- (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
{
return 1.0;
}
Run Code Online (Sandbox Code Playgroud) objective-c ios uicollectionviewcell uicollectionviewdelegate
我在Interface Builder中具有以下笔尖设置,其中包含我的viewController的主视图(带有UICollectionView)以及标头和单元格的可重用视图

我在viewDidLoad中注册可重用的视图
[self.calendarView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"dayCell"];
[self.calendarView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"dayCellDisabled"];
[self.calendarView registerClass:[UICollectionReusableView class] forSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"monthHeader"];
Run Code Online (Sandbox Code Playgroud)
当我尝试像这样访问我的单元格标签时:
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"dayCellDisabled" forIndexPath:indexPath];
UILabel *dayLabel = (UILabel *)[cell viewWithTag:1];
Run Code Online (Sandbox Code Playgroud)
结果dayLabel为nil,因此无法为其分配值,并且视图不显示任何内容。我的可重复使用标题视图及其“年”和“月”标签也是如此。
我在这里做错了什么?
我有一个类文件,它是该类的子UICollectionViewController类。在我的cellForItemAtIndexPath方法中,我试图设置textLabel的单元格。但是,textLabel完成中没有选项。到目前为止,这是方法:
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifier, forIndexPath: indexPath) as UICollectionViewCell
// Configure the cell
cell.backgroundColor = cellColor ? UIColor.blueColor() : UIColor.orangeColor()
//cell.textLabel.text = "Text"???
switch indexPath.item {
case 0...5:
cellColor = true
case 6...13:
cellColor = false
default:
cellColor = true
}
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做才能将其添加textLabel到单元格中?
我一直在研究一个新的应用程序,它在集合视图中显示Gif.我也在我的集合视图中为单元格使用自定义集合视图单元类.
该方法didSelectItemAtIndexPath虽然不起作用......
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
println("it worked")
// ^this did not print
}
Run Code Online (Sandbox Code Playgroud)
我如何更改它以便我可以使用手势识别器获取所单击项目的indexPath?
我有一个UICollectionView,其中每个单元格中都有一个图像。这些图像通过URL加载。但是,当某个单元格滚动出视线时,它会在重新加载之前显示另一单元格的图像一秒钟。我不知道为什么会这样。
这是我的代码:
我的UIImageView扩展要从url加载:
extension UIImageView {
public func imageFromUrl(urlString: String) {
Alamofire.request(.GET, urlString).responseJSON{
response in
if let tilbudimage = UIImage(data: response.data!){
self.image = tilbudimage
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
UICollectionView:
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -> Int {
return 1
}
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
print(DealArr.count)
return DealArr.count
}
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier("DealCell", forIndexPath: indexPath) as! DealCell
let deal = self.DealArr[indexPath.row]
cell.backgroundColor = UIColor.whiteColor()
cell.DealImage.imageFromUrl(deal["image"].string!)
cell.DealLabel.text = deal["title"].string! + …Run Code Online (Sandbox Code Playgroud) 我已经在StackOverflow上搜索了此问题的答案,并尝试了不同的实现方法。我有一个collectionView带有按钮的按钮,当按下该按钮时,它将尝试初始化另一个按钮collectionView。这是堆栈跟踪:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'UICollectionView must be initialized with a non-nil layout parameter'
*** First throw call stack:
(
0 CoreFoundation 0x000000010adb3d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001079b321e objc_exception_throw + 48
2 CoreFoundation 0x000000010ae1d2b5 +[NSException raise:format:] + 197
3 UIKit 0x0000000108eca775 -[UICollectionView initWithFrame:collectionViewLayout:] + 76
4 UIKit 0x0000000108f13abb -[UICollectionViewController _newCollectionViewWithFrame:collectionViewLayout:] + 108
5 UIKit 0x0000000108f12c94 -[UICollectionViewController loadView] + 678
6 UIKit 0x000000010873761c -[UIViewController loadViewIfRequired] + 201
7 UIKit 0x0000000108737e70 -[UIViewController …Run Code Online (Sandbox Code Playgroud) 我在collectionview的自定义单元格中有一个按钮.集合视图位于scrollview上.出于某种原因,我无法点击按钮.我已经检查过我的所有元素都启用了用户交互.
这是我的自定义集合视图单元格:
class MyCollectionViewCell: UICollectionViewCell {
@IBOutlet weak var nameLabel: UILabel!
@IBOutlet weak var connectButton: UIButton!
var onConnectTap: (MyCollectionViewCell) -> Void)?
@IBAction func connectButton(_ sender: Any) {
onConnectTap?(self)
}
func populate(_ user: User) {
nameLabel.text = user.name
}
}
Run Code Online (Sandbox Code Playgroud)
我有一个xib文件,其中按钮的Touch Up Inside事件已连接到connectButton IBAction.
在我的ViewController中:
MyCollectionView.register(UINib(nibName: "MyCollectionViewCell", bundle: nil), forCellWithReuseIdentifier: "cell")
Run Code Online (Sandbox Code Playgroud)
这是我的ViewController中的集合视图函数:
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = myCollectionView.dequeueReusableCell(withReuseIdentifier: "cell", for: indexPath) as! MyCollectionViewCell
let user = users.values[indexPath.row]
cell.populate(user)
cell.onConnectTap = { (cell) …Run Code Online (Sandbox Code Playgroud)