2014-09-29 22 views
-1

當您選擇一個tableviewcell時,它將從44像素擴展到100像素,而當您取消選擇時它將再次收縮到44像素。在底部展開Tableviewcell揭示標籤

在故事板中,我已將自己的單元格定製爲100像素,並添加了3個標籤。一個在頂部,兩個在底部(底部的2個標籤不應該可見並隱藏在底部)。

當我運行我的應用程序時,每個單元格將獲得44像素的高度。底部的兩個標籤在正確的x座標處可見,但在每個其他單元格上方都可見。 這樣的:

This is whats happening to my cells

在viewDidLoad中:

self.expandedIndexPath = [NSIndexPath indexPathForRow:7 inSection:1]; 

而且方法:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    // Compares the index path for the current cell to the index path stored in the expanded 
    // index path variable. If the two match, return a height of 100 points, otherwise return 
    // a height of 44 points. 

    if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) { 
     return 100.0; // Expanded height 
    } 
    return 44.0; // Normal height 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier]; 
    } 
    UILabel *DateName = (UILabel *)[cell viewWithTag:100100]; 
    DateName.text = _objects[indexPath.row]; 
    cell.accessoryType = UITableViewCellAccessoryNone; 
    return cell; 
} 
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    [tableView beginUpdates]; 

if ([indexPath compare:self.expandedIndexPath] == NSOrderedSame) { 
    self.expandedIndexPath = nil; 
} else { 
    self.expandedIndexPath = indexPath; 
} 

[tableView endUpdates]; 
} 

如何隱藏標籤,直至細胞擴增到100個像素?

+0

您是否有任何問題? – 2014-09-29 17:19:01

+0

我編輯了我的問題。 – Dridia 2014-09-29 17:25:50

+0

問題是以'?'結尾的句子。 – 2014-09-29 17:27:02

回答

1

將單元格設置爲clipToBounds = YES;

+0

謝謝!奇蹟般有效! – Dridia 2014-09-29 17:40:49