2015-11-06 98 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

相关问题