2014-01-22 58 views
3

我有一個應用程序加載到一個tableview的動態數據。只有一個項目時(因此只有一個單元格)。爲了確保該UITableViewCellSeperator沒有顯示出來的這一個項目我使用這個代碼:UITableViewCellSeperator出現問題後彈出堆棧

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { 

    // This will create a "invisible" footer 
    return 0.01f; 

} 

可正常工作和這裏是我的手機看起來像:

Cell with no issue

由於你可以看到這個預期的工作,沒有細胞分離器。

當我選擇單元格並顯示我的詳細信息視圖,然後點擊後退按鈕時,單元格出於某種原因添加了分隔符。這裏是細胞看起來像有一次我在棧中向後導航:

Cell with issue

你會發現,分隔符是現在比標準隔板寬。如果我的tableview中有多個單元格,那麼tableview中的最後一個單元格的行爲也是一樣的。

當我刪除上述方法,問題是固定的,但現在我的tableview有一個TON的額外分隔符爲空單元格。有更好的解決方案嗎?

這裏是我的cellForRowAtIndexPath方法:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"searchCell"; 
    UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (!cell) 
    { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; 
    } 

    // Configure the cell... 

    cell.backgroundColor = [UIColor PFBlack]; 

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 

    cell.textLabel.font = [MuseoSans font500WithSize:16.0f]; 
    cell.textLabel.textColor = [UIColor whiteColor]; 
    cell.textLabel.text = @"Current Location"; 


    return cell; 

} 

任何想法是什麼原因造成的問題?或者我做錯了什麼?謝謝!

+0

你找到任何解決這個問題? – kukudas

回答

0

這應該刪除您額外的細胞分離:

tableVie.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero]; 

source

+0

這確實會刪除分隔符,但是當我將某些東西推入堆棧然後將其彈出時,底部單元格中較大/較寬的分隔符仍會再次出現。 –

0

你可以做到這一點通過以下雙向

首先是

[self.tbl setSeparatorStyle:UITableViewCellSeparatorStyleNone]; 

二是

變化,從「默認」
enter image description here
您的實現代碼如下屬性設置爲「無」
enter image description here

+0

這將完全刪除分隔符。我仍然希望他們在tableview中,我只是不想讓多餘的分隔符顯示出來。如果我有兩個項目,分隔符將顯示爲有5個單元格。 –

+0

你能更清楚地闡述它嗎? –