0

ポップオーバーでコレクションビューを表示したい。そこで、最初にコレクションビューコントローラーとカスタムセルを設定しました。ここからプログラムを開始すると、正常に動作します。

別のビューコントローラーで、コレクションビューをコンテンツとして持つポップオーバーコントローラーを作成しました。ツールバーボタンを押すと、ポップオーバーがアクティブになる必要があります。

シミュレーターを実行すると、次のエラーが発生します。

'種類のビューをデキューできませんでした:識別子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;
}

セル識別子は正しく、ストーリーボードセルには適切なカスタムクラスがあります。ストーリーボードにあるカスタムセルを使用しているため、登録する必要はありません。何をすべきか?

4

1 に答える 1

0

あなたの質問から、私はあなたがストーリーボードでセットアップしようとしていることを理解できますUICollectionViewController。プロトタイプセル(I don't have to register because I am using a custom cell that is in the storyboard)を含むコレクションビューが表示されます。私が間違って理解した場合は、それを無視してください。しかし、viewControllerストーリーボードから使用せずに、collectionViewControllerを再度インスタンス化しています。 だから代わりに

UICollectionViewFlowLayout *aFlowLayout = [[UICollectionViewFlowLayout alloc] init];
cameraSystemMenu = [[CameraSystemMenuViewController alloc] initWithCollectionViewLayout:aFlowLayout];  

使用する

UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
    cameraSystemMenu =   [mainStoryboard instantiateViewControllerWithIdentifier:@"CameraSystemMenuViewController"];  

試してみる..:)

于 2013-03-25T14:16:27.240 に答える