我想在彈出窗口中有一個集合視圖。所以首先我設置了我的Collection視圖控制器和我的自定義單元格。當我從這裏啓動程序時,它工作正常。在彈出窗口中使用集合視圖iOS
在另一個視圖控制器中,我創建了一個集合視圖作爲其內容的彈出窗口控制器。當我點擊一個工具欄按鈕時,彈出窗口需要變爲活動狀態。
當我運行模擬器我得到這個錯誤:
'could not dequeue a view of kind: UICollectionElementKindCell with identifier CameraSystemCell - must register a nib or a class for the identifier or connect a prototype cell in a storyboard'
這裏是我的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;
}
單元格標識符正確&故事板單元格具有正確的自定義類。 我不必註冊,因爲我正在使用故事板中的自定義單元格。 怎麼辦?
只是一個疑問'CameraSystemMenuViewController'是collectionViewController?在故事板中設置? – 2013-03-25 14:06:35