Я хочу использовать UICollectionViewController в своем приложении для отображения фотографий.UICollectionViewController: [UICollectionViewController loadView] загрузил значок «идентификатор», но не получил UICollectionView
Я получаю класс от UICollectionViewController как:
#import <UIKit/UIKit.h>
@interface AlbumCollectionViewController : UICollectionViewController <UICollectionViewDataSource, UICollectionViewDelegate>
@property (weak, nonatomic) IBOutlet UICollectionView * cview;
@end
И реализация:
#import "AlbumCollectionViewController.h"
@interface AlbumCollectionViewController()
//@property (weak, nonatomic) IBOutlet UICollectionView * cview;
@end
@implementation AlbumCollectionViewController
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 0;
return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
#warning Incomplete method implementation -- Return the number of items in the section
NSUInteger i = 1;
return i;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];
// Configure the cell
return cell;
}
#pragma mark <UICollectionViewDelegate>
/*
// Uncomment this method to specify if the specified item should be highlighted during tracking
- (BOOL)collectionView:(UICollectionView *)collectionView shouldHighlightItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
// Uncomment this method to specify if the specified item should be selected
- (BOOL)collectionView:(UICollectionView *)collectionView shouldSelectItemAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
*/
/*
// Uncomment these methods to specify if an action menu should be displayed for the specified item, and react to actions performed on the item
- (BOOL)collectionView:(UICollectionView *)collectionView shouldShowMenuForItemAtIndexPath:(NSIndexPath *)indexPath {
return NO;
}
- (BOOL)collectionView:(UICollectionView *)collectionView canPerformAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
return NO;
}
- (void)collectionView:(UICollectionView *)collectionView performAction:(SEL)action forItemAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
}
*/
@end
При загрузке контроллера представления, я получаю
Нагрузочного приложение из-за неперехваченные исключение 'NSInternalInconsistencyException', причина: '- [UICollectionViewController loadView] загрузил ноль «Lyo-Nd-2MQ-view-KhW-kE-Ben», но не получил UICollectionView. '
В главном файле раскадровки у меня есть UICollectionViewController, чей идентификатор класса и раскадровки установлен в 'AlbumCollectionViewController'.
Если мне нужно настроить соединения делегата и источника данных, как я могу это сделать в коде? Или это можно сделать только в файле раскадровки.
Кроме того, если это не похоже на то, что вызывает это, что еще я могу сделать, чтобы исправить это?
Спасибо!
Chris
Почему у вас есть IBOutlet для коллекцииView? У вас уже есть вид контроллера. И еще, почему вы регистрируете наконечник? Вы можете сделать элемент в раскадровке. –
Я работаю над проектом, в котором другие участники делают большую часть материала в коде, поэтому я решил, что лучше или хуже, я постараюсь выполнить это, насколько это возможно. У меня есть IBOutlet, потому что я думал, что это необходимо :). Я долгое время не работал в iOS, поэтому я, возможно, немного ржавый. На данный момент я не знаю, что «слишком много» и/или чего не хватает. – user2011985
Вам не нужен IBOutlet, потому что сам вид контроллера представляет собой коллекцию. –