ios - UICollectionView - 向页脚 View 添加操作

标签 ios objective-c uicollectionview action footer

我有一个带有页脚 View 的 UICollectionView。页脚 View 类是由我创建的。页脚 View 是我想要执行操作的按钮。我试图添加一个 Action ,但当我按下按钮时没有任何反应。请帮助我。

我的代码:

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

最佳答案

试试这个:

添加以下行

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

return (UICollectionReusableView *)footerview;

还要检查您的 todoButton 是否已连接到 Storyboard中的 Button。

关于ios - UICollectionView - 向页脚 View 添加操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31515683/

相关文章:

iPhone文件系统操作问题

ios - Setter 中的静态变量

ios - 如何在 UICollectionViewDelegateFlowLayout 中设置无间距?

ios - Swift CollectionView ReloadData 行为怪异

ios - Youtube 视频播放器定制

ios - 使不可见的 View Controller 的布局无效

ios - 隐藏取消隐藏 UITableViewCell 背景

ios - 核心剧情: should adding a CPTPlotSpaceAnnotation to plot space cause the entire graph to be redrawn?

ios - 如果我开始请求但在 30 秒内没有响应数据,如何在 AFNetworking 中停止请求(超时)

objective-c - 从 NSMutableArray 中的 C-Struct 获取值