I have used UICOllectionView in my app, it worked in IOS 6.0 but when i am trying to run it in IOS7 the collection view is not displayed i saw this question i have tried the answers given there but it dint work, then i have used moveItemAtIndexPath method of collection view and swapped the cells to and fro, then the cells are displayed but when i scroll down the cells again disappeared. The code i used is here
Asked
Active
Viewed 1,271 times
-2
-
i have tried using storyboard but the same problem came.. – BalaChandra Oct 28 '13 at 06:36
-
1Could you please edit your question to include the relevant part(s) of your code? The linked resource will expire in six days and render your question yet less understandable for future visitors... – I'm with Monica Oct 28 '13 at 08:00
-
@AlexanderKosubek i have changed the linked resource.. – BalaChandra Oct 28 '13 at 09:09
1 Answers
3
I study your code & make the changes.
Try this code. 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;
}
Let me know if you have any problem

user1673099
- 3,293
- 7
- 26
- 57
-
-
Please have a look at http://stackoverflow.com/help/how-to-answer: Links to external resources are encouraged, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. – Martin R Oct 28 '13 at 06:53
-
@MartinR, thanks for your explaination. so, Can I write the whole code here? – user1673099 Oct 28 '13 at 06:55
-
1The best answer would be if you *explain* where the problem is, and only post code for the *changes* to make. - (But the same is true for the question: The question should also contain the relevant code.) – Martin R Oct 28 '13 at 06:56
-
@user1673099 yes the code you posted worked but i dint understand what is the problem in my code.. i used your code but modified a small section by copy pasting from my code then it dint work again, but when i do it manually exactly the same changes but without copy-pasting i have changed it manually then again it worked, i dint understand what is the problem – BalaChandra Oct 28 '13 at 07:04
-
@user1673099 ok got it.. i have set the cell.alpha = 0, but it worked fine in iOS 6. – BalaChandra Oct 28 '13 at 07:16
-
@BalaChandra, thanks for accepting my answer.. But where is my up-vote? Happy coding!!! – user1673099 Oct 28 '13 at 07:23