-2

我在我的应用程序中使用了 UICOllectionView,它在 IOS 6.0 中工作,但是当我尝试在 IOS7 中运行它时,集合视图没有显示我看到这个问题我已经尝试了那里给出的答案,但它确实有效,然后我使用了 moveItemAtIndexPath收集视图的方法并来回交换单元格,然后显示单元格,但是当我向下滚动时,单元格再次消失。我使用的代码在这里

4

1 回答 1

3

我研究您的代码并进行更改。

试试这个代码。代码

- (void)viewDidLoad
{
    [super viewDidLoad];
        // Do any additional setup after loading the view, typically from a nib.
    UICollectionViewFlowLayout *layout=[[UICollectionViewFlowLayout alloc] init];
    _collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(130, 100, 780, 1024) collectionViewLayout:layout];
    _collectionView.autoresizesSubviews= YES;
    [_collectionView setDataSource:self];
    [_collectionView setDelegate:self];
    _collectionView.backgroundColor = [UIColor clearColor];

    [_collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:@"cellIdentifier"];

    [self.view addSubview:_collectionView];

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return 12;
}
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    UICollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"cellIdentifier" forIndexPath:indexPath];
    UIView *headertitle = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 375, 20)];
    UILabel *titlelabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 20)];
    titlelabel.text = [NSString stringWithFormat:@"graphtitle%d",indexPath.row];
    titlelabel.textColor = [UIColor blackColor];
    titlelabel.font = [UIFont fontWithName:@"Knewave" size:15.0f];
    titlelabel.backgroundColor = [UIColor clearColor];
    [headertitle addSubview:titlelabel];
    headertitle.backgroundColor = [UIColor whiteColor];
    UIWebView *web = [[ UIWebView alloc]initWithFrame:CGRectMake(0, 20, 375, 150)];
    NSString *htmlFile = [[NSBundle mainBundle] pathForResource:@"test" ofType:@"html"];
    NSData *htmlData = [NSData dataWithContentsOfFile:htmlFile];
    web.scalesPageToFit = YES;
    [web loadData:htmlData MIMEType:@"text/html" textEncodingName:@"UTF-8" baseURL:[NSURL URLWithString:@""]];
    UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
    button1.backgroundColor = [UIColor clearColor];
    button1.frame = CGRectMake(320, 3, 50, 17);
    [button1 setTitle:@"view" forState:UIControlStateNormal];

    [headertitle addSubview:button1];
    headertitle.backgroundColor = [UIColor grayColor];

    [cell addSubview:headertitle];
    [cell addSubview:web];

    cell.layer.shadowColor = [[UIColor blackColor]CGColor];
    cell.layer.shadowOffset = CGSizeMake(20, 20);
    cell.layer.borderColor = [[UIColor blackColor] CGColor];
    cell.layer.borderWidth =1;
    //cell.alpha = 1.0f; //Changed here   
    return cell;
}

如果您有任何问题,请告诉我

于 2013-10-28T06:43:19.280 回答