我在Storyboard中使用自定义CollectionViewCell.当我启动应用程序时,我收到此消息:
无法将"UICollectionViewCell"类型的值转换为TestProject.CollectionViewCell.
我正在尝试更新内部的单个单元格UICollectionView,特别是我只是尝试更新引爆的特定单元格中的图像cell.imageView.[self.collectionView reloadData]不是一个真正的选择,因为它使整个集合视图闪烁.似乎[self.collectionView beginUpdates]不是一件好事UICollectionView.
我知道我可以使用:
[self.collectionView performBatchUpdates:^{
//do something
} completion:nil];
Run Code Online (Sandbox Code Playgroud)
我不确定在完成块内放置什么来更新某个单元格imageView.这一切都是在内部完成的didSelectItemAtIndexPath.我也没有使用NSFetchedResultsController.有任何想法吗?
objective-c uitableview ios uicollectionview uicollectionviewcell

1)如何实现如图所示UICollectionView?
2)我尝试了-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath方法并传递了不同的大小,但它在单元格之间留下了空间.我可以清空这些空间吗?我希望每个细胞都有不同的高度和宽度
当前输出:
.
objective-c ios uicollectionview uicollectionviewcell uicollectionviewlayout
发生了什么
目前我有一个使用两个UICollectionViews内部的应用程序UITableView.这样我创建了一个类似应用程序的Pulse News.我的问题是,有时第6行和第11行完全消失,留下一个空白区域应该是单元格.我真的不介意,如果所有细胞都是这样的(这种方式我可以假设我没有做正确的事情),但问题是,正好发生在那些特定的细胞上.
我的理论
第6行和第11行是我开始滚动时出现的行,所以默认情况下我可以看到5个单元格,当我进行第一次水平滚动时,第6行会出现(有时会出现空白).
是)我有的
我目前唯一要做的就是:
[self.collectionView registerNib:[UINib nibWithNibName:CELL_NIB_NAME bundle:nil] forCellWithReuseIdentifier:CELL_IDENTIFIER];
Run Code Online (Sandbox Code Playgroud)
在viewDidLoad.在创建细胞时:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MyCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CELL_IDENTIFIER forIndexPath:indexPath];
NSMutableDictionary *dictionary = [self.DataSource objectAtIndex:[indexPath row]];
[cell buildViewWithDictionary:dictionary withReferenceParent:self.referenceViewController];
return cell;
}
Run Code Online (Sandbox Code Playgroud)
所以在我的承诺中没有任何幻想在这里发生.我虽然在数据源(虚拟JSON文件)上有问题,但有时它工作正常并且单元格显示,所以我猜从那部分是可以的.
所以我的"问题":有谁知道发生了什么?我真的不想说这是来自iOS的错误,但我想不出别的什么.
编辑1.0
令人惊讶的是这种方法
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath;
Run Code Online (Sandbox Code Playgroud)
在indexPath不计算[0,5]的情况下从[0,4]变为[0,6].我第一次真正在iOS中看到这种情况.
编辑2.0
我已经改变了创建单元格的方式,而不是出列我使用旧方法:
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:CELL_NIB_NAME owner:self options:nil];
MyCell *cell = (MyCell *)[nib objectAtIndex:0];
Run Code Online (Sandbox Code Playgroud)
仍然是同样悲伤的结果.
我有一个大小与屏幕大小相同的UICollectionView.它显示的UICollectionViewCells与collectionView的大小相同.每个细胞都有一个UIImage,它是细胞的大小.CollectionView启用了分页,因此它实际上是用户可以滑动的全屏照片幻灯片.
问题是
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath只有当用户用两根手指敲击一个小区或长按一根手指然后释放时才会被调用.它似乎没有单击选择的默认行为.我没有对CollectionView手势识别器进行任何更改,因此无法找到解决此问题的方法.
我有一个UICollectionView与segmented control数据之间切换.但是如何以编程方式更改UICollectionViewCell大小属性?然后我可以为每种数据类型适当地定制每种样式.
例如,将宽度更改为520点,将高度更改为100.我是iOS开发新手,对CSS有经验:/
我知道如何在Xcode中做(显然),但不知道在swift中更改它的正确方法.非常感谢任何想法或反馈(Y)
我有一个简单的UICollectionView,单元格有一个UITextView.UITextView受限于单元格的边缘,因此它们应保持与单元格大小相同的大小.
我遇到的问题是,由于某种原因,当我通过collectionView指定单元格大小时,这些约束不起作用:layout:sizeForItemAtIndexPath:.
我在故事板中将单元格大小设置为320x50.如果我使用sizeForItemAtIndexPath:返回大小为单元格大小2倍的大小,则尽管我设置了约束,但UITextView仍保持相同的高度.我正在使用Xcode 6 GM.
我的视图控制器代码是:
@implementation TestViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
UICollectionViewCell *c = [self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0]];
NSLog(@"%f", c.frame.size.height);
UITextView *tv = (UITextView *)[c viewWithTag:9];
NSLog(@"%f", tv.frame.size.height);
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
return cell;
}
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
UICollectionViewFlowLayout *flowLayout = (UICollectionViewFlowLayout *)collectionView.collectionViewLayout; …Run Code Online (Sandbox Code Playgroud) 我如何才能找到indexPath用于cell在中间UICollectionView?
我有水平滚动,只有一个大cell的可见(cell两侧的其他部分也是可见的).我需要删除cell位于中心(手段 - 当前cell)而不触摸它.
只需按"废纸篓"按钮并确认删除.但现在它只删除了第一个cells.
- (void)actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
if (buttonIndex == actionSheet.destructiveButtonIndex) {
initialPinchPoint = ????????
self.tappedCellPath = [self.collectionView indexPathForItemAtPoint:initialPinchPoint];
Technique *technique = [arrayOfTechnique objectAtIndex:self.tappedCellPath.row];
[self deleteData:[NSString stringWithFormat:@"DELETE FROM TECHNIQUES WHERE TECHNIQUENAME IS '%s'",[technique.techniquename UTF8String]]];
[arrayOfTechnique removeObjectAtIndex:self.tappedCellPath.row];
//[arrayOfTechnique removeObjectAtIndex:[custom_layout ]];
[self removeImage:technique.techniquename];
[self.collectionView performBatchUpdates:^{
[self.collectionView deleteItemsAtIndexPaths:[NSArrayarrayWithObject:self.tappedCellPath]];
} completion:nil];
[self checkArrayCount];
}
}
Run Code Online (Sandbox Code Playgroud) 我的UICollectionView单元格包含带有多行文本的UILabel.在标签上设置文本之前,我不知道单元格的高度.
-(CGSize)collectionView:(UICollectionView *)collectionView
layout:(UICollectionViewLayout*)collectionViewLayout
sizeForItemAtIndexPath:(NSIndexPath *)indexPath;
Run Code Online (Sandbox Code Playgroud)
这是我查看细胞大小的初始方法.但是,这是在故事板之外创建单元格之前调用的.
有没有办法布置集合并在细胞渲染后调整大小,我知道细胞的实际大小?
这不是一个问题,而是解释如何解决这个问题.
首先要意识到的是,它UICollectionView确实继承了UIScrollView- 所以使用滚动视图的内容进行标准查找是最好的解决方案.
这是我要解决的问题:
我有一个UICollectionView在每个细胞中都有不同的项目 - 以及不同类型的细胞.我需要选择一个单元格,以使单元格中的图像效果显示为扩展并占据整个屏幕.我如何进行扩展是另一篇文章.
挑战在于让细胞在屏幕上的位置,以便动画部分具有从哪里开始的参考点.
因此,为了便于获取此信息,请考虑以下代码:
第一点:
UICollectionView *picturesCollectionView;
DrawingCell cell; // -> instanceof UICollectionViewCell with custom items.
// first, get the list of cells that are visible on the screen - you must do this every time
// since the items can change... This is a CRITICAL fact. You do not go through the
// entire list of cells - only those the collectionView indicates are visible. Note
// there …Run Code Online (Sandbox Code Playgroud) uicollectionview ×10
ios ×8
objective-c ×4
swift ×2
xcode ×2
autolayout ×1
ipad ×1
uitableview ×1