2014-04-02 71 views
1

我正在iOS 7.0上開發我的第一個使用Xcode 5.1的iPad應用程序,並且我使用的是UICollectionViewUICollectionView單元在秒數或錄像屏幕後消失

Here is an sketch of my storyboard

我CollectionViewController被納入我最初的控制器的看法時,我點擊導航欄中的第一個選項卡中。

細胞在幾秒鐘後消失或當我在屏幕上點擊某處時消失。

如果我把CollectionViewController作爲初始視圖控制器,單元格就可以!

我不明白! 請幫助。

#import "ActiviteViewController.h" 
#import "AppDelegate.h" 
#import "Embarcation.h" 
#import "CollectionActiviteCellController.h" 

@interface ActiviteViewController() 

@end 

@implementation ActiviteViewController 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; } 

- (void) viewWillAppear: (BOOL) animated { 
    [super viewWillAppear:animated]; 
    [[self view] setFrame: CGRectMake(0, 0, 1024, 618)]; } 


-(BOOL)shouldInvalidateLayoutForBoundsChange:(CGRect)newBounds { 
    return YES; } 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    AppDelegate* appDelegate = [UIApplication sharedApplication].delegate; 

    // Fetching Records and saving it in "fetchedRecordsArray" object 
    self.embarcationsArray = [appDelegate getAllPayments]; 
    [self.collectionView reloadData]; } 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. } 

- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView { 
    // Return the number of sections. 
    return 1; } 

- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section { 
    // Return the number of rows in the section. 
    return [self.embarcationsArray count]; } 

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath { 
    CollectionActiviteCellController *myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"MonEmbarcation" 
forIndexPath:indexPath]; 

    Embarcation * embarcation = [self.embarcationsArray objectAtIndex:indexPath.row]; 
    myCell.labelEmbarcation.text = [NSString stringWithFormat:@"%@, %@ ",embarcation.nom,embarcation.etat]; 

    NSLog([NSString stringWithFormat:@"%@, %@ ",embarcation.nom,embarcation.etat]); 

    return myCell; } 

/* 
#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. } 
*/ 

@end 
+0

您是否正確設置了您的數據源?當您用來填充collectionCells的數組爲空時,您可能正在執行reloadData。還有你的註冊CustomCell?無論哪種方式。發佈所有與CollectionView相關的代碼 –

+0

我發佈了所有revenant代碼,我試圖刪除reloadData但沒有任何變化 –

+0

無需刪除reloadData:O!你只需要檢查你的'embarcationsArray'中的狀態和數據。你可以替換'[appDelegate getAllPayments];'用硬編碼數組作爲實驗?此外,我沒有看到你註冊你的單元格(或提到這一點),所以你可以添加這行到你的viewDidLoad方法? [self.collectionView registerClass:[CollectionActiviteCellController class] forCellWithReuseIdentifier:@「CollectionActiviteCellController」] ;.順便說一句我假設你正確設置你的'CollectionActiviteCellController'來擴展'UICollectionViewCell'! –

回答

0

通過代碼或Storyboard將dataSource插座連接到您的視圖控制器。

代碼:

self.collectionView.delegate = self; 

或通過故事板CTRL +拖動從集合視圖代表您的視圖控制器對象的黃色矩形,比選擇「數據源」。

Outlets dragged from collection view