2013-03-25 6 views
0

popover에서 콜렉션 뷰를 원합니다. 먼저 콜렉션 뷰 컨트롤러와 사용자 정의 셀을 설정합니다. 여기에서 프로그램을 시작하면 제대로 작동합니다.popover에서 콜렉션 뷰 사용 iOS

다른보기 컨트롤러에서 컬렉션보기를 내용으로하는 팝 오버 컨트롤러를 만들었습니다. 툴바 버튼을 누르면 popover가 활성화되어야합니다.

다음

'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은? 스토리 보드에 설치 ??? –

답변

0

내가 이해할 수있는 것은 스토리 보드에 UICollectionViewController을 설정하려고한다는 것입니다. 프로토 타입 셀 (I don't have to register because I am using a custom cell that is in the storyboard)이있는 콜렉션 뷰를 제공합니다. 내가 잘못 이해했다면 그냥 무시하십시오. 그러나 viewController에서는 다시 storyboard에서 사용하지 않고 collectionViewController를 인스턴스화합니다. 그래서 대신

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

사용

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

의 사용 해보세요 .. :)

+0

그게 나를 위해 작동합니다! 당신의 도움을 주셔서 감사합니다!!! –

관련 문제