UI集合视图未在iOS 7中显示

时间:2013-10-28 06:11:25

标签: ios objective-c uicollectionview

我在我的应用程序中使用了UICOllectionView,它在IOS 6.0中运行但是当我尝试在IOS7中运行它时,不会显示集合视图i saw this question我已经尝试了那里给出的答案,但它有效,然后我已经使用了集合视图的moveItemAtIndexPath方法并来回交换了单元格,然后显示了单元格,但是当我向下滚动单元格时又消失了。我使用的代码是here

1 个答案:

答案 0 :(得分:3)

我研究你的代码&做出改变。

试试这段代码。 Code

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

如果您有任何问题,请与我们联系