桌面与自定义UIView,添加标签重叠

问题描述:

我试图实现ibooks书架功能,我使用GSBookShelf这是非常简单和直接,它添加按钮作为单元格,它的作品很棒。桌面与自定义UIView,添加标签重叠

我想为每个按钮添加一些标签,但我偶尔可以说一次5个标签中的2个与前面的按钮标签重叠。

通常这样 normally like this

有时出现这种情况: Sometime this happens

代码:

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

形象都不错,他们从来没有重叠,但标签是否有时。

任何想法,为什么发生这种情况?

你把bookShelfView函数放在哪里?显示你的TableView代码。我敢打赌,你所遇到的问题是,当你在表bookShelfView中再次被调用时向下滚动。您的标签正在为两个不同的值创建两次。

这就是你看到的重叠发生的唯一途径,这是正在开始一遍又一遍

_fileLabel =[[UILabel alloc] initWithFrame:CGRectMake(0, 180, 200, 46)]; 

我会检查你的TableView代码。我之前曾问过类似的问题。 (不确切)。检查出来UITableView and UILabel repeating

+0

谢谢,我最终标记每个标签,并在每次分配新标签之前从超级视图中删除它 –