Reputation: 4914
I am trying to implement ibooks bookshelf like functionality and I use GSBookShelf which is pretty simple and straight forward, it adds button as cells and it works great.
I want to add some labels to each button, I succeed but once in a while lets say 2 out of 5 times labels overlaps from previous buttons label.
normally like this
Sometime this happens:
Code:
- (UIView *)bookShelfView:(GSBookShelfView *)bookShelfView bookViewAtIndex:(NSInteger)index {
NSDictionary *currentArticle = [_bookArray objectAtIndex:index];
static NSString *identifier = @"bookView";
MyBookView *bookView = (MyBookView *)[bookShelfView dequeueReuseableBookViewWithIdentifier:identifier];
if (bookView == nil) {
bookView = [[MyBookView alloc] initWithFrame:CGRectZero];
bookView.reuseIdentifier = identifier;
[bookView addTarget:self action:@selector(bookViewClicked:) forControlEvents:UIControlEventTouchUpInside];
}
[bookView setIndex:index];
[bookView setSelected:[(NSNumber *)[_bookStatus objectAtIndex:index] intValue]];
//[bookView setFileName:[currentArticle objectForKey:@"name"] ];
//[bookView setFileName:[currentArticle objectForKey:@"name"] :index];
UIImage *image = nil;
image = [self returnCellImagefor:[currentArticle objectForKey:@"imagename"]];
[bookView setBackgroundImage:image forState:UIControlStateNormal];
UILabel *_fileLabel=nil;
_fileLabel =[[UILabel alloc] initWithFrame:CGRectMake(0, 180, 200, 46)];
_fileLabel.text=[currentArticle objectForKey:@"name"];
_fileLabel.textColor=[UIColor whiteColor];
_fileLabel.backgroundColor=[UIColor clearColor];
_fileLabel.font = [UIFont fontWithName:@"Gill Sans" size:16];
//_fileLabel.textAlignment=UITextAlignmentCenter;
_fileLabel.textAlignment = NSTextAlignmentCenter;
_fileLabel.numberOfLines=0;
_fileLabel.lineBreakMode = UILineBreakModeWordWrap;
[_fileLabel sizeToFit];
[bookView addSubview:_fileLabel];
return bookView;
}
Images are good they never overlap but label does it sometimes.
Any idea why this is happening?
Upvotes: 0
Views: 241
Reputation: 27608
Where did you put bookShelfView function at? Show your TableView code. I bet the problem you have is that when you scroll down in table bookShelfView is being called again. Your label is being created twice for two different values.
That's the only way you see that overlap happening, this is being initiated over and over again
_fileLabel =[[UILabel alloc] initWithFrame:CGRectMake(0, 180, 200, 46)];
I would check your TableView Code. I had asked a similar question before. (not exact). Check it out UITableView and UILabel repeating
Upvotes: 1