2013-03-25 43 views
0

我想在彈出窗口中有一個集合視圖。所以首先我設置了我的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; 
} 

單元格標識符正確&故事板單元格具有正確的自定義類。 我不必註冊,因爲我正在使用故事板中的自定義單元格。 怎麼辦?

+0

只是一個疑問'CameraSystemMenuViewController'是collectionViewController?在故事板中設置? – 2013-03-25 14:06:35

回答

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"]; 

給一個嘗試.. :)

+0

這對我很有用!謝謝你的幫助!!! – 2013-03-25 14:20:26