【发布时间】:2013-04-27 16:40:59
【问题描述】:
我正在使用 Storyboard 在单元格内创建 UICollectionViewController - CollectionView - Cell(我自己的 DasboardsViewCell)和我的客户视图(DashBoardView)。我正确连接了所有东西,除了上下滚动之外,一切似乎都正常工作。我会在调试后解释我的理解。
此外,我的 DashBoardView 自定义视图中有 2 个视图,我使用“一个”作为主要主视图,其他视图作为 FlipView(例如,当用户点击单元格时)。由于所有内容都是从故事板连接的,因此我不必为重用而注册类。
1) 在我的 DashboardCustomView 中(上面还有 2 个其他视图)我这样做
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
_isPrimary = YES;
//to init my 2 child views and insert to main custom view
[self initSubViewsWithInsert];
}
return self;
}
2) 在我的 DashBoardViewCell 类中,我这样做
@synthesize dashBoardView = _dashBoardView;
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
self.backgroundColor = [UIColor colorWithWhite:0.75f alpha:0.6f];
self.layer.borderColor = [UIColor blackColor].CGColor;
self.layer.borderWidth = 2.0f;
self.layer.cornerRadius = 7.0f;
}
return self;
}
// If I dont do this below I get overlapped images and data on cell when scrolling up and down
- (void)prepareForReuse
{
self.dashBoardView.mainContainerView = nil;
self.dashBoardView.flipView = nil;
}
3) 现在,在此之后,我仍然看到自定义视图出现故障,并且似乎比不对我的视图执行“nil”要好一些,但问题是,一旦我将 2 个子视图归零,我就没有定义的重新初始化方法当我的 collectionview 控制器重新排列单元格并开始添加我的内容时。
即我确实喜欢这个 cellForItemAtIndexPath
if ([cell isKindOfClass:[DashboardsViewCell class]]) {
DashboardsViewCell *dashCell = (DashboardsViewCell*) cell;
Dashboard* tmpDashboard = self.availableDashBoards[indexPath.item];
[dashCell.dashBoardView addDashboardImageViewAtPoint:tmpDashboard.identifier
usingIndexPath:indexPath];
上面的最后一行是在仪表板主视图上添加一些图像和文本,即 self.dashBoardView.mainContainerView 并且它已经为零。
有人可以帮助我了解是否有明确的方法可以做到这一点。另外,如果您认为我看错了问题
【问题讨论】:
标签: ios storyboard uicollectionview