UICollectionView - 向页脚视图添加操作

时间:2015-07-20 11:46:05

标签: ios objective-c uicollectionview action footer

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

我的代码:

FViewController.m

HttpPostedFile file = Request.Files["myFile"];

if (file != null && file.ContentLength > 0 && (Path.GetExtension(file.FileName) == ".xlsx" || Path.GetExtension(file.FileName) == ".xls"))
        {
            StreamReader reader = null;
            StringBuilder data = new StringBuilder();
            string value = "";

            CultureInfo cultureSp;
            Encoding encodingSp;
            cultureSp = CultureInfo.GetCultureInfo("es-ES");
            encodingSp = Encoding.GetEncoding(cultureSp.TextInfo.ANSICodePage);

            using (reader = new StreamReader(file.InputStream))
            {
                while ((value = reader.ReadLine()) != null)
                {
                    data.AppendLine(value); 
                }
            }
            escribirExcel.InnerHtml = encodingSp.GetString(Encoding.Default.GetBytes(data.ToString()));

        }
        else
            escribirExcel.InnerHtml = "ERROR";

    }        

FooterCollectionReusableView.h

- (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];
}

3 个答案:

答案 0 :(得分:1)

试试这个:

添加以下行

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

return (UICollectionReusableView *)footerview;

另外检查你的todoButton是否与故事板中的Button连接。

答案 1 :(得分:0)

这就是发生的事情:

  

你是否在故事板中将todoButton与按钮联系起来?

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

谢谢Lalit Kumar

答案 2 :(得分:0)

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