Ios Don';不显示UICollectionViewController
我试图在Xcode 6上使用Ios Don';不显示UICollectionViewController,ios,objective-c,xcode,xcode6,Ios,Objective C,Xcode,Xcode6,我试图在Xcode 6上使用UICollectionViewController,但我看不到自定义单元格或原型项。我用白色将标签放在单元格中,实现了numberOfSections和numberOfItemsInSection,但问题仍然存在。你能帮我吗?提前谢谢 @implementation CollectionViewController static NSString * const reuseIdentifier = @"Cell"; - (void)viewDidLoad {
UICollectionViewController
,但我看不到自定义单元格或原型项。我用白色将标签放在单元格中,实现了numberOfSections和numberOfItemsInSection,但问题仍然存在。你能帮我吗?提前谢谢
@implementation CollectionViewController
static NSString * const reuseIdentifier = @"Cell";
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = NO;
// Register cell classes
[self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:reuseIdentifier];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark <UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
#warning Incomplete method implementation -- Return the number of sections
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete method implementation -- Return the number of items in the section
return 5;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// Configure the cell
return cell;
}
@实现集合视图控制器
静态NSString*const reuseIdentifier=@“Cell”;
-(无效)viewDidLoad{
[超级视图下载];
//取消注释下一行以保留演示文稿之间的选择
//self.clearselectiononviewwillappear=否;
//注册单元类
[self.collectionView注册表类:[UICollectionViewCell类]forCellWithReuseIdentifier:reuseIdentifier];
//加载视图后执行任何其他设置。
}
-(无效)未收到记忆警告{
[超级记忆警告];
//处置所有可以重新创建的资源。
}
/*
#pragma标记-导航
//在基于故事板的应用程序中,您通常需要在导航之前做一些准备
-(void)prepareForSegue:(UIStoryboardSegue*)segue发送方:(id)发送方{
//使用[segue destinationViewController]获取新的视图控制器。
//将选定对象传递给新的视图控制器。
}
*/
#布拉格标记
-(NSInteger)collectionView中的节数:(UICollectionView*)collectionView{
#警告:方法实现不完整--返回节数
返回1;
}
-(NSInteger)collectionView:(UICollectionView*)collectionView项目编号截面:(NSInteger)截面{
#警告:方法实现不完整--返回节中的项数
返回5;
}
-(UICollectionViewCell*)collectionView:(UICollectionView*)collectionView cellForItemAtIndexPath:(NSIndexPath*)indexPath{
UICollectionViewCell*cell=[collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
//配置单元格
返回单元;
}
尝试在以下位置设置一些数据:cellForItemAtIndexPath
我的代码的一个小例子
- (UICollectionViewCell *)collectionView:(UICollectionView *)cv cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
MEMediaView *cell = [cv dequeueReusableCellWithReuseIdentifier:@"MEMediaView" forIndexPath:indexPath];
[cell awakeFromNib];
[cell setMemryMediaData:[mediaArray_ objectAtIndex:indexPath.row]];
[cell setMediaContent];
if (shadow)
{
[cell shadeCoverImage];
}
return cell;
}
另外,不要忘记设置代理:
self.collectionView.delegate = self;
self.collectionView.dataSource = self;
我编辑我的unswear请尝试在连接检查器上使用此选项,我不知道为什么会出现此问题,UITableViewController这没问题,但UICollectionViewController我显示黑屏,我使用原型单元格更改背景颜色,但问题仍然存在。解决方案是删除[self.collectionview registerClass:[NewCell class]forCellWithReuseIdentifier:@“Cell”];在storybord,我们不需要这个。