2014-03-24 18 views
8

我的應用程序包含一個UITableView它有部分頁腳。當用戶滾動到tableView的底部時,有時會在最後一個單元格和tableFooter之間出現分隔符插入。這種行爲是不一致的。UITableView底部分隔符插入 - 在IOS 7中的奇怪行爲

enter image description here

enter image description here

有沒有辦法迫使該分離器總是出現或不會出現?你們有沒有注意到這種不一致的行爲?對我來說就像一個錯誤。

編輯
我使用

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    UILabel *footer = [[UILabel alloc] init]; 

    footer.backgroundColor = [UIColor whiteColor]; 

    footer.font = [footer.font fontWithSize:15]; 
    footer.textAlignment = NSTextAlignmentCenter; 

    return footer; 
} 

,但你可以很容易地重現同樣的問題只能用

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section; 

enter image description here

enter image description here

+0

你在'viewForFooter ...'中的代碼是什麼? – Fogmeister

+0

您是否得到了解決方案? –

+0

我建議你跳過默認tableView分隔符瘋狂,並將其設置爲不可見: [_tableView setSeparatorColor:[UIColor clearColor]];然後,簡單地將UIView子視圖添加到每個單元格,這將與框架CGRectMake(0,0,_tableview.frame.size.width,1),然後也隱藏它,如果單元格行是0.這樣,它也將更加一致與以前的iOS版本,也可以使用自定義分隔線圖像(如果需要..)或自定義顏色或從兩側插入位置。 –

回答

0

要做到THI您必須覆蓋用作頁腳的標準UIView

您可以通過覆蓋委託方法-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section來做到這一點。

-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    UIView *myFooterView; 

    // create a view with a label and without a line at the top etc... 

    return myFooterView; 
} 
+0

我已經使用viewForFooterInSection。無論如何,該錯誤與該方法完全無關,因爲如果您使用它或不使用它,就會發生這種錯誤。 – user3250560

+0

啊,我在你編輯你的問題之前提出了我的回答。 – Fogmeister

0

我不知道爲什麼你會得到不一致的結果。也許嘗試添加背景到頁腳視圖。這裏是我的代碼:

-(UIView *) tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section 
{ 
    UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 33)]; 
    [footerView setBackgroundColor:[UIColor grayColor]]; 
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, footerView.bounds.size.width, 20)]; 
    label.text = @"Footer"; 
    [label setTextAlignment:NSTextAlignmentCenter]; 

    [footerView addSubview:label]; 

    return footerView; 
} 

這裏是結果:

enter image description here

+0

我添加了更多圖像以顯示問題。即使您設置了「backgroundColor」,也會發生同樣的問題。 – user3250560

0

這一點做的懶辦法,但它的工作沒有少。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifyer"]; 

    if (indexPath.row == tableArray.count) { 
     cell.separatorStyle = UITableViewCellSeparatorStyleNone; 
    } 

    return cell; 

} 
+2

您不能在單個單元格上設置'separatorStyle'。並設置'cell.separatorInset = UIEdgeInsetsMake(無論);'沒有幫助。 – user3250560

+0

@ user32050560我很確定我爲iOS 7中的單個單元格設置了cell.separatorInset(當我隱藏下面的行時,通常是分組tableview中某個節中的最後一個可見單元格)。你是你的答案嗎? – SAHM

0

這裏是解決方案,非常簡單!

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CellIdentifyer"]; 

    cell.separatorInset = (indexPath.row == totalNumber-1) ? UIEdgeInsetsMake(0, INT16_MAX, 0, 0) : UIEdgeInsetsZero; 

    return cell; 

} 
0

我發現了一些關於它的解決方法:

每當你想到這個額外的分離器可能出現(例如,當用戶滾動到下像你描述的) - 添加幾行代碼:

tableView.separatorStyle = UITable​View​Cell​Separator​Style​None; 
tableView.separatorStyle = UITable​View​Cell​Separator​Style​Single​Line; 

邏輯是這樣的:第一個字符串代碼刪除底部分隔符,第二個不添加它。它在某些情況下適用於我,但它不是100%修復。

我想,它可能也是一個蘋果的bug,因爲有時底部分隔符會在他們的'提醒'應用程序中消失。