ポップオーバーでコレクションビューを表示したい。そこで、最初にコレクションビューコントローラーとカスタムセルを設定しました。ここからプログラムを開始すると、正常に動作します。
別のビューコントローラーで、コレクションビューをコンテンツとして持つポップオーバーコントローラーを作成しました。ツールバーボタンを押すと、ポップオーバーがアクティブになる必要があります。
シミュレーターを実行すると、次のエラーが発生します。
'種類のビューをデキューできませんでした:識別子CameraSystemCellを持つUICollectionElementKindCell-識別子のペン先またはクラスを登録するか、ストーリーボードのプロトタイプセルを接続する必要があります'
これが私のviewcontroller.mコードです:
#import "ViewController.h"
#import "CameraSystemMenuViewController.h"
@interface ViewController () <UIPopoverControllerDelegate>
{
CameraSystemMenuViewController *cameraSystemMenu;
UIPopoverController *popoverController;
}
@end
@implementation ViewController
@synthesize cameraSystemButton = _cameraSystemButton;
- (void)viewDidLoad
{
[super viewDidLoad];
UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init];
cameraSystemMenu = [[CameraSystemMenuViewController alloc] initWithCollectionViewLayout:aFlowLayout];
popoverController = [[UIPopoverController alloc] initWithContentViewController:cameraSystemMenu];
[popoverController setDelegate:self];
}
- (IBAction)cameraSystemSelectButton:(id)sender
{
[popoverController presentPopoverFromBarButtonItem:sender permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[popoverController setPopoverContentSize:CGSizeMake(320, 400)];
}
@end
そしてこれがCameraSystemMenuViewController.mの私のcellForItemAtIndexPathです:
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CameraSystemCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"CameraSystemCell" forIndexPath:indexPath];
[[cell collectionImageView] setImage:cameraImage];
cell.cameraSystemName.text = [cameraNumbers objectAtIndex:indexPath.item];
return cell;
}
セル識別子は正しく、ストーリーボードセルには適切なカスタムクラスがあります。ストーリーボードにあるカスタムセルを使用しているため、登録する必要はありません。何をすべきか?