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

标题: ios - 创建后一段时间在 UICollectionView 的 Header View 上调用方法 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-12 11:57
标题: ios - 创建后一段时间在 UICollectionView 的 Header View 上调用方法

我在 UICollectionView 的标题 View 中有一个 UIWebview。我想在创建标题 View 后调用 updateDataObject 将 url 传递给 UIWebview,一段时间后

TestViewController(开启了 UICollectionView)

- (UICollectionReusableView *)collectionViewUICollectionView *)collectionView viewForSupplementaryElementOfKindNSString *)kind atIndexPathNSIndexPath *)indexPath


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

    if (kind == UICollectionElementKindSectionHeader) {
        AdViewHeaderView *headerView = [collectionView dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeader withReuseIdentifier"AdViewHeaderView" forIndexPath:indexPath];
        reusableview = headerView;
        headerTmp = headerView;
        headerView.sectionMyLikeLabel.text = @"My Likes Here";
    }
    return reusableview;
}
...

NSURLConnection *httpCollection ... (this is to fetch the url link passed to the UIWebview);

   ....

   - (void)connectionDidFinishLoadingNSURLConnection *)connection {
    // here I get the link and want to call the header's updateDataObject
    } 

标题 View 。

#import <UIKit/UIKit.h>

@interface AdViewHeaderView : UICollectionReusableView

@property (strong, nonatomic) UILabel *sectionLabel;
@property (strong, nonatomic) UIWebView *promotionView;

-(void)updateDataObjectNSString *)link;

@end

为了防止headerview的内存被回收。我尝试创建一个名为

的属性
@property (nonatomic, strong) AdViewHeaderView *headerImp;

在 TestViewController 中。然后稍后在connectionDidFinishLoading里面,我可以调用这个方法

[headerImp updateDataObject...]

但是,10 次中有 1 次 headerImp 已被回收并变为空。有什么想法吗?

问候 锤子



Best Answer-推荐答案


编辑问题后回复:

作为一个collectionView,每个部分可以有一个标题 View 。也许滚动会创建多个 headerViews 而不是一个(对于 indexPath.section == 0)。

关于ios - 创建后一段时间在 UICollectionView 的 Header View 上调用方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26138153/






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