【问题标题】:UI collection view not displayed in iOS 7iOS 7 中未显示 UI 集合视图
【发布时间】:2013-10-28 06:11:25
【问题描述】:

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

【问题讨论】:

  • 我尝试过使用故事板,但同样的问题来了..
  • 您能否编辑您的问题以包含代码的相关部分?链接的资源将在 6 天后过期,这会使您的问题对未来的访问者不太容易理解...
  • @AlexanderKosubek 我已更改链接资源..

标签: ios objective-c uicollectionview


【解决方案1】:

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

试试这个代码。 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;
}

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

【讨论】:

  • 这对您有帮助吗?
  • 请查看stackoverflow.com/help/how-to-answer:鼓励链接到外部资源,但请在链接周围添加上下文,以便您的其他用户了解它是什么以及为什么存在。始终引用重要链接中最相关的部分,以防目标站点无法访问或永久离线。
  • @MartinR,感谢您的解释。那么,我可以在这里写整个代码吗?
  • 最好的答案是您解释问题出在哪里,并且只发布更改的代码。 - (但问题也是如此:问题还应包含相关代码。)
  • @user1673099 是的,您发布的代码有效,但我不明白我的代码中有什么问题.. 我使用了您的代码,但通过从我的代码中复制粘贴修改了一小部分,然后它再次起作用,但是当我手动进行完全相同的更改但没有复制粘贴时,我手动更改了它,然后它再次起作用,我不明白是什么问题
猜你喜欢
  • 2021-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-20
  • 1970-01-01
  • 2015-12-17
相关资源
最近更新 更多