UICollectionView单元格在几秒钟后或录制屏幕时消失

时间:2014-04-02 10:22:33

标签: ios objective-c uicollectionview uicollectionviewcell

我正在iOS 7.0上使用Xcode 5.1开发我的第一个iPad应用程序,而我正在使用UICollectionView

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

1 个答案:

答案 0 :(得分:0)

通过代码或故事板将dataSource插座连接到视图控制器。

代码:

self.collectionView.delegate = self;

或通过storyboard ctrl +从集合视图拖动到表示视图控制器对象的黄色矩形,然后选择“dataSource”。

Outlets dragged from collection view