Tôi đang cố gắng hiển thị UICollectionView bên trong trình điều khiển chế độ xem được trình bày có phương thức. Ứng dụng cho iPad iOS 7.Không thể hiển thị UICollectionView để hiển thị các ô
tôi đã tạo ra lớp con của UIViewController (với một ngòi) và thêm nó như thế này:
MyViewController *controller = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.modalPresentationStyle = UIModalPresentationFullScreen;
navController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[self presentViewController:navController animated:YES completion:nil];
điều khiển Quan điểm này là trở thành đại biểu và nguồn dữ liệu cho UICollectionView của tôi vì vậy tôi đã thêm UICollectionViewDataSource và UICollectionViewDelegate vào tiêu đề.
Tôi đã đặt một UICollectionView vào ngòi bút và thêm một lối thoát để MyViewController:
@property (strong, nonatomic) IBOutlet MyCollectionView *collectionViewController;
Tôi đã thêm này trong viewDidLoad trong MyViewController:
self.collectionViewController.dataSource = self;
self.collectionViewController.delegate = self;
Tôi cũng đã thêm theo sau MyViewController:
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
NSLog(@"Items in section: %d", itemsArray.count); // returns correct amount
return itemsArray.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
NSLog(@"cellForItemAtIndexPath %@", indexPath); // returns as expected
static NSString *identifier = @"MyCell";
[self.collectionViewController registerClass:[MyCollectionCell class] forCellWithReuseIdentifier:identifier];
MyCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identifier forIndexPath:indexPath];
UIImageView *myImageView = (UIImageView *)[cell viewWithTag:100];
myImageView.image = [UIImage imageNamed:[itemsArray objectAtIndex:indexPath.row]];
return cell;
}
Tôi cũng đã thiết lập một lớp con của UICollection ViewCell với số nhận dạng được đặt thành MyCell và được thêm vào UIImageView với thẻ 100.
Bất cứ khi nào tôi hiển thị bộ điều khiển chế độ xem này, tôi sẽ nhận được thanh điều hướng như mong đợi, nhưng chế độ xem UICollection tôi đã thêm vào nib là hư không để được nhìn thấy. Tất cả những gì tôi thấy là màu đen, nơi chế độ xem bộ sưu tập nên có. Nếu tôi thay đổi màu nền của MyCollectionView từ mặc định thành trắng, tôi sẽ thấy màu trắng, nơi chế độ xem bộ sưu tập phải là. Dường như nó sẽ hiển thị MyCollectionView, nhưng không hiển thị bất kỳ ô nào.
[Bạn đã làm theo hướng dẫn của Appcoda?] (Http://www.appcoda.com/ios-collection-view-tutorial/) –