2013-07-11 37 views
0

我試圖實現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; 
} 

形象都不錯,他們從來沒有重疊,但標籤是否有時。

任何想法,爲什麼發生這種情況?

回答

1

你把bookShelfView函數放在哪裏?顯示你的TableView代碼。我敢打賭,你所遇到的問題是,當你在表bookShelfView中再次被調用時向下滾動。您的標籤正在爲兩個不同的值創建兩次。

這就是你看到的重疊發生的唯一途徑,這是正在開始一遍又一遍

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

我會檢查你的TableView代碼。我之前曾問過類似的問題。 (不確切)。檢查出來UITableView and UILabel repeating

+0

謝謝,我最終標記每個標籤,並在每次分配新標籤之前從超級視圖中刪除它 –