我有2个嵌套的UICollectionViews.外部集合视图的委托是主视图控制器,内部集合视图委托是外部集合视图的UICollectionCell.
外部集合视图只有一个标签和内部集合视图 - 通常会有七个,内部集合视图应包含3或4个单元格(包含3个标签).
问题是内部集合视图似乎只是在重复之后才更新两次(对于外部视图中的前两组数据).
这是外部UICollectionView的cellForItemAtIndexPath
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Main Tide Data Table Cell";
TideDataTableCell* tideDayDataCell = [self.tideDataTable dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
tideDayDataCell.tideDataTable.delegate = tideDayDataCell;
tideDayDataCell.tideDataTable.dataSource = tideDayDataCell;
tidalDate* tideDate = self.tidalDates[indexPath.row];
tideDayDataCell.thisTidalDate = tideDate;
tideDayDataCell.dayLabel.text = tideDate.dateString;
tideDayDataCell.averageTideHeight = self.avgTideHeight;
tideDayDataCell.backgroundColor = [UIColor whiteColor];
self.tideDataTable.backgroundColor = [UIColor lightGrayColor];
return tideDayDataCell;
}
Run Code Online (Sandbox Code Playgroud)
...这里是第二个UICollectionView的cellForItemAtIndexPath,它位于UICollection视图的UICollectionViewCell对象中!
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSString* CellIdentifier = @"Tide Info Table Cell";
TidalTideTableCell* tidalTideTableCell = [self.tideDataTable dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
tidalTideTableCell.timeTideLabel.text …Run Code Online (Sandbox Code Playgroud) 我正在尝试设置一个UICollectionView.起初我使用的是基本的UICollectionViewCell,它运行良好,细胞正在显示.
然后我创建了自己的collectionViewCell(子类化UICollectionViewCell),以便能够在单元格中显示图像.我将Storyboard中的自定义单元格与标识符相关联,并且还为其指定了正确的类.
但是,我一直有这个错误,我不明白为什么:
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'could not dequeue a view of kind: UICollectionElementKindCell with identifier MediaCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
Run Code Online (Sandbox Code Playgroud)
我设法通过添加这一行来处理这个bug,viewDidLoad但在我关注的教程中,这些人没有使用它:
[self.collectionView registerClass:[MediaCollectionViewCell class] forCellWithReuseIdentifier:@"MediaCell"];
Run Code Online (Sandbox Code Playgroud)
问题是如果我添加它,collectionView将保持黑色并且不显示任何数据.
iphone cocoa-touch ios uicollectionview uicollectionviewcell
我有一个水平的集合视图,其代码用于突出显示/为所选单元格着色.它突出显示所选的单元格,但之后每5个单元格也会突出显示.知道发生了什么事吗?
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
{
for(int x = 0; x < [cellArray count]; x++){
UICollectionViewCell *UnSelectedCell = [cellArray objectAtIndex:x];
UnSelectedCell.backgroundColor = [UIColor colorWithRed:0.2 green:0.5 blue:0.8 alpha:0.0];
}
UICollectionViewCell *SelectedCell = [cellArray objectAtIndex:indexPath.row];
SelectedCell.backgroundColor = [UIColor colorWithRed:0.2 green:0.5 blue:0.8 alpha:1.0];
cellSelected = indexPath.row;
NSLog(@"%i", cellSelected);
}
Run Code Online (Sandbox Code Playgroud) 我有一个UICollectionView像工具选择容器一样使用的东西.你有很多工具(单元格),当你选择一个工具时,取消选择前一个选择,依此类推......你一次只能选择一个工具.
问题是我无法设法选择单元格.当我点击单元格时,collectionView:didSelectItemAtIndexPath:会调用它.然后我重新加载选定的单元格来改变它的外观(我改变alpha了图像)[collectionView reloadItemsAtIndexPaths:@[indexPath]].
好吧,重新加载单元格确定,除了一个该死的东西:在collectionView:cellForItemAtIndexPath:单元格中永远不会将selected属性设置为YES!所以我永远不能改变它,alpha因为我不知道什么时候我必须画一个选定的单元格.
更糟糕的[collectionView indexPathsForSelectedItems]是:永远是空的!
我甚至没有提到collectionView:didDeselectItemAtIndexPath:从未被称为......
好吧,如果有人能帮我理解发生的事情,请提前感谢...
objective-c selection ios uicollectionview uicollectionviewcell
我需要画一个圆UICollectionViewCell。盘旋与另外色的边界和背景颜色。我的代码。
UICollectionViewController
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CalendarCell *cell;
firstDayInMonth = [self dayWeekStart:[self getDateFromItem:dateFromStart section:indexPath.section row:1]];
if (indexPath.row < firstDayInMonth) {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellCalendarEmpty" forIndexPath:indexPath];
} else {
cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cellCalendar" forIndexPath:indexPath];
if ([self compareOnlyDate:[self getDateFromItem:dateFromStart section:indexPath.section row:indexPath.item-firstDayInMonth] date2:[self getDateLocaleTimeZone:[NSDate date]]] == 1) {
cell.bgColor = [UIColor blueColor];
cell.titleLabel.textColor = [UIColor whiteColor];
cell.drawCircle = [NSNumber numberWithInt:1];
toDaySection = indexPath.section;
} else {
cell.bgColor = [UIColor whiteColor];
cell.drawCircle = [NSNumber numberWithInt:0];
cell.titleLabel.textColor = [UIColor lightGrayColor]; …Run Code Online (Sandbox Code Playgroud) 我有一个来自UIcollectionViewCell的自定义单元格Subclassed.通过代码,我创建了按钮,并在同一个类中使用target方法添加到单元格中.
按钮事件工作正常.但我需要控制到我创建UICollectionView的基本视图.
所以为此我创建了自定义委托来识别点击事件.
---> DBDraggingCell.h文件
@protocol DBDraggingCellDelegate <NSObject>
-(void)chartButtonpressed:(id)sender;
-(void)accountHistoryButtonpressed:(id)sender;
-(void)transactionHistoryButtonpressed:(id)sender;
@end
@interface DBDraggingCell : UICollectionViewCell{
UIButton *chartButton;
UIButton *accSummaryButton;
UIButton *transactionHistory;
}
Run Code Online (Sandbox Code Playgroud)
////////////////////////////////////////////
-(void)chartPressed:(UIButton *)sender{
[_delegate chartButtonpressed:sender];
}
_delegate returns nil
----> In baseview i have set the delegate
[self addSubview:_theCollectionView];
_theCollectionView.delegate=self;
Not working
The methods inside the baseview not called
Run Code Online (Sandbox Code Playgroud) 我有多个集合视图需要使用相同的原型单元格.现在,我在故事板中复制每个集合视图中的原型单元格(如下所示).这不是很干,在对单元格进行故事板更改时会变得很痛苦.
是否可以在故事板中的一个位置定义单元格?
或者我尝试只使用1个集合视图,但我无法获得单元格堆叠和垂直滚动的3列布局,因此我移动到3个集合视图.
objective-c storyboard ios uicollectionview uicollectionviewcell
我是iOS和Swift的新手.
设法使用自定义LayoutAttributes和可重复使用的自定义单元格创建UICollectionView,该单元格计算图像的高度.这一切都很棒.工作正常,我可以手动滚动.都好.
问题是我想以编程方式滚动到第N个indexPath,但scrollToItemAtIndexPath似乎只适用于可见的.
所以我需要2列图像,在iphone 5S上显示9张图像.图像总数为31.
因此,使用collectionView的ScrollToItemAtIndexPath可以处理第9项.
但是,当我尝试进一步以编程方式滚动时,比如12,它不起作用.奇怪的是,如果手动滚动,然后调用代码,它的工作原理.所以我调试了一下,看到只有前9个单元格的高度计算.那会是问题吗?如果是这样,我怎么能让它工作?
尝试过使用didLayoutSubviews和其他人的建议,但它没有用.
目前,我正在使用didSelectItemAtIndexPath collectionView功能以编程方式滚动.
编辑:
override func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let item = self.collectionView(self.collectionView!, numberOfItemsInSection: 0) - 1
let lastItemIndex = NSIndexPath(forItem: item, inSection: 0)
self.collectionView?.scrollToItemAtIndexPath(lastItemIndex, atScrollPosition: UICollectionViewScrollPosition.CenteredVertically, animated: true)
}
Run Code Online (Sandbox Code Playgroud)
即使我硬编码索引路径的编号(例如12),它仍然不起作用.如果需要更多信息,请告诉我.
我在这里错过了什么吗?
非常感谢.
我正在尝试编写可扩展的UICollectionViewCell.如果用户按下顶部按钮,则单元格应扩展到不同的高度并显示底层内容.
我的第一个实现具有自定义UICollectionViewCell,可以通过单击顶部按钮进行扩展,但collectionview也不会扩展.自动取款机.单元格是collectionview中的最后一个单元格,只需向下滑动,就可以看到展开的内容.如果你停止触摸,滚动视图会跳起来,看不到扩展单元格.
这是我的代码:
import Foundation
import UIKit
class ExpandableCell: UICollectionViewCell {
@IBOutlet weak var topButton: IconButton!
public var expanded : Bool = false
private var expandedHeight : CGFloat = 200
private var notExpandedHeight : CGFloat = 50
@IBAction func topButtonTouched(_ sender: AnyObject) {
if (expanded == true) {
self.deExpand()
} else {
self.expand()
}
}
public func expand() {
UIView.animate(withDuration: 0.8, delay: 0.0, usingSpringWithDamping: 0.9, initialSpringVelocity: 0.9, options: UIViewAnimationOptions.curveEaseInOut, animations: {
self.frame = CGRect(x: self.frame.origin.x, y: self.frame.origin.y, width: self.frame.size.width, height: …Run Code Online (Sandbox Code Playgroud) 我正在以编程方式进行所有操作,避免使用情节提要。我有一个collectionView,一个Post拥有用户名和密码的模型对象,当然我有collectionView单元格。我遇到的问题是,我的collectionView单元格内部有一个按钮。我希望能够点击此按钮并选择一个新的控制器。这是简单的部分。问题在于,我不仅要检入新控制器,还要传递我点击的按钮的特定Post Cell的特定用户名。我希望这是有道理的。基本上,我想拥有一个帖子,就像任何社交媒体应用程序一样,我想选择一个“个人资料”,并且还将该特定用户的用户名也传递给该个人资料控制器。希望您能理解。由于我在此问题上停留了一段时间,因此将给予任何帮助,我们将不胜感激。我当然会标记为答案。感谢大伙们...
class MyController: UICollectionViewController, UICollectionViewDelegateFlowLayout {
var posts = [Post]()
override func viewDidLoad() {
super.viewDidLoad()
collectionView?.backgroundColor = .white
collectionView?.register(CustomCell.self, forCellWithReuseIdentifier: "cellId")
}
override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return posts.count
}
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: view.frame.width, height: 50)
}
override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: "cellId", for: indexPath) …Run Code Online (Sandbox Code Playgroud) uitableview uicollectionview uicollectionviewcell swift swift3
ios ×8
objective-c ×5
swift ×3
iphone ×2
cocoa-touch ×1
drawrect ×1
selection ×1
storyboard ×1
swift3 ×1
uitableview ×1
xcode ×1