gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:14:01 25 4
gpt4 key购买 nike

我有一个带有页脚 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com