這是處理:我有一個UITableView,有兩個部分,當第一個部分爲空時我想顯示一個「無數據」單元,以便2個部分標題爲不要粘在一起(導致它看起來很奇怪)。當部分爲空時,UITableView的背景顏色變爲白色
它的效果很好(即使我在開始工作時遇到麻煩,see this thread)。我使用viewForFooterInSection:
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
if(section == 0)
{
if([firstSectionArray count] == 0)
return 40;
else
return 0;
}
return 0;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
if(section == 0)
{
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(200, 10, 50, 44)];
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor colorWithWhite:0.6 alpha:1.0];
label.textAlignment = UITextAlignmentCenter;
label.lineBreakMode = UILineBreakModeWordWrap;
label.numberOfLines = 0;
label.text = @"No row";
return [label autorelease];
}
return nil;
}
但底色變成純白色的,當我顯示部分頁腳視圖。見圖片:
alt text http://img683.yfrog.com/img683/9480/uitableviewproblem.png
我比較喜歡當背景填充空單元格。有沒有人有任何想法如何做到這一點?謝謝
我已經試過了,但我得到當我刪除最後一個NSInternalInconsistencyException該部分的行:'無效更新:部分0中的行數無效。在更新(1)之後,現有部分中包含的行數必須等於更新之前該部分中包含的行數(1) ,加上或減去從該部分插入或刪除的行數(0插入,1刪除)。' 這讓我瘋狂! – nmondollot 2009-12-13 10:34:30
我已經更新了答案,向你展示瞭如何處理這個問題:)你確實需要去該行的行數爲0,但是還有一些工作要做...... – 2009-12-13 21:28:53
謝謝你多卓然!有用! (儘管仍然有點黑客,但我想我們在這裏沒有選擇...) – nmondollot 2009-12-14 15:22:32