【问题标题】:UICollectionView - Add action to footer viewUICollectionView - 将动作添加到页脚视图
【发布时间】:2015-10-09 12:39:51
【问题描述】:

我有一个带有页脚视图的 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

【问题讨论】:

  • 删除UITapGestureRecognizer后试试
  • 我试过了,但没有任何反应......
  • 你用断点了吗?你的 todosPush 是否被调用了
  • 试试这个return (UICollectionReusableView *)footerview;
  • 您是否已将todoButton 与情节提要中的按钮连接

标签: ios objective-c uicollectionview action footer


【解决方案1】:

试试这个:

添加以下行

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

return (UICollectionReusableView *)footerview;

还要检查您的 todoButton 是否连接到情节提要中的 Button。

【讨论】:

    【解决方案2】:

    事情是这样的:

    您是否将 todoButton 与情节提要中的按钮连接?

    我忘记了连接按钮 :( 现在可以使用了

    谢谢拉利特库马尔

    【讨论】:

      【解决方案3】:
      - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout referenceSizeForFooterInSection:(NSInteger)section
      {
          CGSize footersize = CGSizeMake([UIScreen mainScreen].bounds.size.width, 20);
          return footersize;
      }
      

      【讨论】:

        猜你喜欢
        • 2016-03-10
        • 1970-01-01
        • 2014-10-01
        • 2014-02-26
        • 2016-08-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-09-23
        相关资源
        最近更新 更多