作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有一个带有页脚 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/
我是一名优秀的程序员,十分优秀!