2011-03-04 21 views
2

我遇到兩個問題:自定義標題中的tableview使用UITableView的自定義頁眉放緩的iPhone 3G與3.1.3

1)大的是自定義頁眉都在放緩了不少列表的滾動一個真正的iPhone 3G 3.1.3,而在模擬器或真正的iPad上仍然是完美的。這是我使用的代碼:

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

    UIView *headerView = [[HeaderView alloc] init]; 
    headerView.alpha = 0.7; 

    UITextView *label = [[UITextView alloc] initWithFrame:CGRectZero]; 
    label.textColor = [UIColor whiteColor]; 

    switch (section) { 
     case 0: 
      label.text = @"Mattina"; 
      break; 
     case 1: 
      label.text = @"Pomeriggio"; 
      break; 
     case 2: 
      label.text = @"Sera"; 
      break; 
     default: 
      label.text = @""; 
      break; 

    } 

    [headerView addSubview:label]; 

    return headerView; 
} 

2)使用上面的代碼標題標籤不顯示...哪裏的錯誤?

謝謝!

回答

0

緩慢是由泄漏引起的。解決的辦法是簡單地設置headerView對象的自動釋放:

UIView *headerView = [[[HeaderView alloc] init] autorelease]; 
0

@Abramodj我認爲你需要做的

[label setBackgroundColor:[UIColor clearColor]]; 
+0

這是不會改變什麼... – Abramodj 2011-03-04 09:33:30

+0

你可以把默認塊'label.text = @「默認」;'和檢查程序再次。 – Robin 2011-03-04 09:49:28

+0

仍然一樣......不過感謝您的幫助! ;-) – Abramodj 2011-03-04 10:16:47

1

我看到這兩個問題:

  1. 你爲什麼要設置標籤的框架CGRectZero?它沒有默認設置autoresizing屬性,所以它不會伸展以適合Headerview。

    label.autoresizingMask = UIViewAutoresizingFlexibleWidth;

  2. 爲什麼您使用的UITextView代替的UILabel:你可以設置寬度和高度明確,只是可以肯定的,但是這可能做的伎倆?這並不是廣爲人知,但UITextView在放置在可滾動視圖後顯示內容時遇到了一些問題。它並不總是正確刷新。此外,這是過度使用,我個人覺得它能夠在另一個滾動視圖中滾動視圖,即UITableView中的UITextView,這是違反直覺的。

+0

你是對的! – Abramodj 2011-03-24 17:35:16