我UIcollectionView在Uinavigationviewcontroller後,我的應用程序的第一個視圖只是故事板就像這樣:沒有在UIcollectionView控制器apear
這是我RootViewController.h
#import <UIKit/UIKit.h>
@interface RootViewController : UICollectionViewController<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic, strong) NSArray *entries;
@end
和我RootViewController.m:
#import "RootViewController.h"
#import "AppRecord.h"
#import "Cell.h"
#define kCustomRowCount 7
@interface RootViewController() <UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout>
// the set of IconDownloader objects for each app
@property (nonatomic, strong) NSMutableDictionary *imageDownloadsInProgress;
@end
@implementation RootViewController
#pragma mark
// -------------------------------------------------------------------------------
// viewDidLoad
// -------------------------------------------------------------------------------
- (void)viewDidLoad
{
NSLog(@"inside class");
[super viewDidLoad];
// self.title = @"My Title";
//self.collectionView.delegate = self;
//self.collectionView.dataSource=self;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
NSUInteger count = [self.entries count];
NSLog(@"count: %lu", (unsigned long)count);
if (count == 0)
{
return kCustomRowCount;
}
return count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
NSLog(@"inside cell");
AppRecord *appRecord = [self.entries objectAtIndex:indexPath.row];
Cell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MY_CELL" forIndexPath:indexPath];
UIImage *truckImage = [[UIImage alloc] init];
truckImage = [UIImage imageNamed:@"Default.png"];
cell.imageView.image = truckImage;
return cell;
}
@end
現在的問題是我的「cellForItemAtIndexPath」或「numberOfItemsInSection」或甚至「viewDidLoad」被調用,並且模擬器上的輸出是黑屏。
這是AppDelegate類的重載我部分:
__block ParseOperation *weakParser = parser;
parser.completionBlock = ^(void) {
if (weakParser.appRecordList) {
dispatch_async(dispatch_get_main_queue(), ^{
RootViewController *rootViewController = (RootViewController*)[(UINavigationController*)self.window.rootViewController topViewController];
rootViewController.entries = weakParser.appRecordList;
if(weakParser.appRecordList != nil)
NSLog(@"weakParser.appRecordList is Not nill");
[rootViewController.collectionView reloadItemsAtIndexPaths:[rootViewController.collectionView indexPathsForVisibleItems]];
[rootViewController.collectionView reloadData];
});
}
self.queue = nil;
};
[self.queue addOperation:parser];
self.appListData = nil;
}
從Ray Wenderlich教程開始。幾乎有數百個地方可以找到答案。當你與他們卡住,然後來到這裏。你需要首先了解他們是如何工作的。 – Fogmeister
我對uitableview和iVE沒有任何問題,在「Ray Wenderlich」教程中提到的一切都是這樣的: http://www.raywenderlich.com/22324/beginning-uicollectionview-in-ios-6-part-12 dont知道爲什麼我堅持在這裏很糟糕 –