滚动视图中的iOS 7集合视图

时间:2013-12-02 21:43:05

标签: ios objective-c uiscrollview ios7 uicollectionview

我正在使用故事板开发UICollectionViewUIScrollView的应用程序。 我在故事板和代码中设置了委托和dataSource

我正在使用虚假信息来验证应用的布局,但UICollectionViewUICollectionViewCell不会以任何方式出现。

.M

@implementation PerfilUsuarioViewController
- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title =  @"Perfil";
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"fundo@2X.png"]];
    FotosHelper* fotoCasal = [[FotosHelper alloc]init];

    //Tamanho da view que sera exibida
    self.scrollView.contentSize = CGSizeMake(310, 1160);
    //Tamanho da tela do aparelho
    self.scrollView.frame = CGRectMake(0, 0, 320, 568);

    [self preparaZPositionCamposDetalhesCasal];
    [self dadosPessoaUm];

    self.fotosCollectionView.delegate = self;
    self.fotosCollectionView.dataSource = self;

    self.labelNmCasal.text = [NSString stringWithFormat:@"%@ (%ld)", self.usuario.usuarioNome, self.usuario.usuarioCodigo];
    self.fotoCasal.image = [fotoCasal decodeBase64ToImage:self.usuario.usuarioFotoPerfil];
    self.fieldProposta.text = self.usuario.usuarioDescricao;
}

//inner methods

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionHeader) {
        TituloCollectionViewCell *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];
        NSString *title = [[NSString alloc]initWithFormat:@"Recipe Group #%i", indexPath.section + 1];
        headerView.labelTitulo.text = title;

        reusableview = headerView;
    }
    return reusableview;
}


(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    FotosCollectionViewCell *cell = (FotosCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.fotoCollectionViewCell.image = [UIImage imageNamed:@"feminino.png"];

    if (cell.selected) {
        cell.backgroundColor = [UIColor blueColor]; // highlight selection
    }
    else
    {
        cell.backgroundColor = [UIColor redColor]; // Default color
    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath  {

    FotosCollectionViewCell *datasetCell = (FotosCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
    datasetCell.backgroundColor = [UIColor blueColor]; // highlight selection
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {

    FotosCollectionViewCell *datasetCell = (FotosCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
    datasetCell.backgroundColor = [UIColor redColor]; // Default color
}

</code>

.H

@implementation PerfilUsuarioViewController
- (void)viewDidLoad {
    [super viewDidLoad];

    self.navigationItem.title =  @"Perfil";
    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"fundo@2X.png"]];
    FotosHelper* fotoCasal = [[FotosHelper alloc]init];

    //Tamanho da view que sera exibida
    self.scrollView.contentSize = CGSizeMake(310, 1160);
    //Tamanho da tela do aparelho
    self.scrollView.frame = CGRectMake(0, 0, 320, 568);

    [self preparaZPositionCamposDetalhesCasal];
    [self dadosPessoaUm];

    self.fotosCollectionView.delegate = self;
    self.fotosCollectionView.dataSource = self;

    self.labelNmCasal.text = [NSString stringWithFormat:@"%@ (%ld)", self.usuario.usuarioNome, self.usuario.usuarioCodigo];
    self.fotoCasal.image = [fotoCasal decodeBase64ToImage:self.usuario.usuarioFotoPerfil];
    self.fieldProposta.text = self.usuario.usuarioDescricao;
}

//inner methods

-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
    return 1;
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return 10;
}

-(UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath {

    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionHeader) {
        TituloCollectionViewCell *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier:@"headerView" forIndexPath:indexPath];
        NSString *title = [[NSString alloc]initWithFormat:@"Recipe Group #%i", indexPath.section + 1];
        headerView.labelTitulo.text = title;

        reusableview = headerView;
    }
    return reusableview;
}


(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    FotosCollectionViewCell *cell = (FotosCollectionViewCell*)[collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];

    cell.fotoCollectionViewCell.image = [UIImage imageNamed:@"feminino.png"];

    if (cell.selected) {
        cell.backgroundColor = [UIColor blueColor]; // highlight selection
    }
    else
    {
        cell.backgroundColor = [UIColor redColor]; // Default color
    }
    return cell;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath  {

    FotosCollectionViewCell *datasetCell = (FotosCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
    datasetCell.backgroundColor = [UIColor blueColor]; // highlight selection
}

-(void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {

    FotosCollectionViewCell *datasetCell = (FotosCollectionViewCell*)[collectionView cellForItemAtIndexPath:indexPath];
    datasetCell.backgroundColor = [UIColor redColor]; // Default color
}

</code>

0 个答案:

没有答案