2015-11-06 100 views
0

我正在使用自定義表格視圖單元格,如果一行是奇數,那麼我必須給填充10左右的單元格,否則沒有填充。我在自定義表格視圖類中使用了setFrame,如下所示。但是它爲所有單元格填充填充。我只想給奇數行填充填充。提前感謝您的幫助。如何更改ios目標c中特定單元格的自定義表格視圖單元格的框架?

- (void)setFrame:(CGRect)frame { 
     frame.origin.x += 10; 
     frame.size.width = frame.size.width - 20; 
     [super setFrame:frame]; 

} 

回答

3

將屬性添加到您的自定義單元格中,如布爾值。 然後在SETFRAME:

- (void)setFrame:(CGRect)frame { 
    if(self.isOdd) { 
     frame.origin.x += 10; 
     frame.size.width = frame.size.width - 20; 
    } 
    [super setFrame:frame]; 
} 

然後

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    [...] 
    //check if your cell is odd or not 
    if(theCellIsOdd) 
     [theCell setIsOdd:YES]; 
    else 
     [theCell setIsOdd:NO]; 
    [...] 
    return theCell; 

} 
+0

你是真棒。非常感謝 – Sakthimuthiah

+0

這真的一直工作嗎?過去我曾經在細胞的框架上增加了尺寸,因爲它們被重用;所以我傾向於用#define靜態設置所需的尺寸 – Alex

相關問題