OGeek|极客世界-中国程序员成长平台

标题: ios - UICollectionView - 将 Action 添加到页脚 View [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 09:07
标题: ios - UICollectionView - 将 Action 添加到页脚 View

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

我的代码:

FViewController.m

- (UICollectionReusableView *)collectionViewUICollectionView *)collectionView viewForSupplementaryElementOfKindNSString *)kind atIndexPathNSIndexPath *)indexPath
{
    UICollectionReusableView *reusableview = nil;

    if (kind == UICollectionElementKindSectionFooter) {

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

        [footerview.todoButton addTarget:self actionselector(todosPush forControlEvents:UIControlEventTouchUpInside];


        reusableview = footerview;
    }

    return reusableview;
}

-(IBAction)todosPushid)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



Best Answer-推荐答案


试试这个:

添加以下行

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

return (UICollectionReusableView *)footerview;

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

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






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4