2015-07-20 3 views
1

У меня есть UICollectionView с нижним колонтитулом. Класс нижнего колонтитула создается мной. Представление нижнего колонтитула - это кнопка, которую я хочу применить. Я попытался добавить одно действие, но ничего не произошло, когда я нажал кнопку. Пожалуйста, помогите мне.UICollectionView - Добавить действие в нижний колонтитул

Мой код:

FViewController.m

- (UICollectionReusableView *)collectionView:(UICollectionView *)collectionView viewForSupplementaryElementOfKind:(NSString *)kind atIndexPath:(NSIndexPath *)indexPath 
{ 
    UICollectionReusableView *reusableview = nil; 

    if (kind == UICollectionElementKindSectionFooter) { 

    FooterCollectionReusableView *footerview = [[FooterCollectionReusableView alloc] init]; 
    footerview = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath]; 

     [footerview.todoButton addTarget:self action:@selector(todosPush:) forControlEvents:UIControlEventTouchUpInside]; 


     reusableview = footerview; 
    } 

    return reusableview; 
} 

-(IBAction)todosPush:(id)sender{ 

    NSLog(@"todosPush"); 
    UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; 
    TipoEjercicioViewController *tipo = [storyBoard instantiateViewControllerWithIdentifier:@"TipoEjercicioView"]; 
    tipo.ejercicio = 22; 
    [self.navigationController pushViewController:tipo animated:YES]; 
} 

FooterCollectionReusableView.h

@interface FooterCollectionReusableView : UICollectionReusableView 

@property (nonatomic, retain) IBOutlet UIButton * todoButton; 

@end 
+0

попробовать после удаления 'UITapGestureRecognizer' –

+0

Я пытался, но ничего не происходит .... – amurcia

+0

вы использовали точка останова? ваш todosPush вызывается или нет –

ответ

1

Попробуйте это:

Добавить следующие строки

FooterCollectionReusableView *footerview = (FooterCollectionReusableView *)[collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionFooter withReuseIdentifier:@"FooterView" forIndexPath:indexPath]; 

и

return (UICollectionReusableView *)footerview; 

Также проверьте, ваш todoButton подключен к кнопке в раскадровке или нет.

+0

Подключить кнопку решить проблему :) – amurcia

0

Это то, что случилось:

будет подключен todoButton с помощью кнопки в раскадровке?

Я забыл подключить де кнопку :(теперь он работает

Спасибо LaLit Кумар

0
- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section 
{ 
    CGSize footersize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 20); 
    return footersize; 
}