2011-11-08 46 views
0

我想爲我的UITableView自定義外觀,包含頁眉,頁腳和單元格的圖像。對於這個問題,我返回一個UIImageView作爲表格的頁眉和頁腳,並且我還設置了UIImageView作爲單元的backgroundViewUITableViewCell寬度太窄(以分組風格)

問題是單元格的圖像比頁眉/頁腳窄。這似乎是分組風格UITableView的默認行爲。我需要一個分組樣式,以便滾動時標題不會與單元格重疊。

有沒有辦法解決這個問題?

回答

0

對不起我可憐的英語,我可以讓你失望。但是,如果沒有錯誤:如果您找不到「正確」解決方案,您可以嘗試以下操作: (這不是您做任何事情的最佳方式,但它是我能夠提供的唯一方法)

所有你需要的只是一個部分,沒有標題,使你的表視圖。然後,使每個「原始」必須是具有不同參數的另一段的標題:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView 
    { 
     return 1; 
    } 

    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
    { 
     return <number of all raws in all sections plus number of sections, to make some raws - sections>; 
    } 
    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    for (int i = 0; i < (number of sections); i++) { 
     if (indexPath.raw == i*(number of raws in section i)) return (heigth of header); 
} 
    return (heigth of raw); 

    } 

    //Configure cells: 

    - (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] autorelease]; 
     } 

     // Configure the cell... 
     for (int i = 0; i < (number of sections); i++) if (indexPath.raw == i*(number of raws in section i)) { 
    //set properties to headers 
    return cell; 
    } 

    //set properties to raws 
    return cell; 
    }