【问题标题】:Use a collection view in a popover iOS [closed]在弹出窗口iOS中使用集合视图[关闭]
【发布时间】:2013-03-25 13:43:10
【问题描述】:

我想在弹出窗口中有一个集合视图。所以首先我设置了我的 Collection 视图控制器和我的自定义单元格。当我从这里启动程序时,它工作正常。

在另一个视图控制器中,我创建了一个以集合视图作为其内容的弹出框控制器。当我点击工具栏按钮时,弹出框需要变为活动状态。

当我运行模拟器时出现此错误:

' 无法将一种视图出列:UICollectionElementKindCell with 标识符 CameraSystemCell - 必须为 标识符或连接故事板中的原型单元'

这是我的 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?在情节提要中设置???

标签: ios objective-c ipad popover collectionview


【解决方案1】:

根据您的问题,我可以理解您正在尝试在情节提要中设置 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"];  

试一试..:)

【讨论】:

  • 这对我有用!谢谢你的帮助!!!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多