Storyboard を使用して UICollectionViewController - CollectionView - セル (自分の DasboardsViewCell) とセル内の顧客ビュー (DashBoardView) を作成しています。すべてを正しく配線したところ、上下にスクロールする場合を除いてすべてが機能しているようです。デバッグした後、私の理解が何であるかを説明します。
また、DashBoardView カスタム ビュー内に 2 つのビューがあり、「1 つ」をメイン プライマリとして使用し、もう 1 つを 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 つのサブビューを nil アウトすると、それらを再初期化する方法が定義されていないことです。 collectionview controller はセルを再キューイングし、コンテンツの追加を開始します。
つまり、私はこの 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 に画像とテキストを追加していますが、既に nil になっています。
これを行うための定義された方法があるかどうかを誰かが理解するのを手伝ってくれますか? また、私が間違った問題を見ていると思われる場合