以编程方式实例化子类化的 uitableviewCell initwithstyle 不显示分隔符



在iOS5.0中 我正在尝试使用 initwithstyle 以编程方式实例化一个子类化的 uitableviewcell。 我使用的代码如下。当我使用 UITableViewCell 分配实例化时...我得到了表格分隔符,但是当我使用 thumbCell 分配这样做时,表格行分隔符行没有出现,我在 thumbCell 中设置的文本没有出现。并且屏幕显示为全白..请帮助我了解我做错了什么..

在我的视图控制器中

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *identifier = @"GroupCell";
    thumbCell *cell = [self.testTableView dequeueReusableCellWithIdentifier:identifier];
    //UITableViewCell *cell = [self.testTableView dequeueReusableCellWithIdentifier:identifier]; (this works)
    if(!cell) {
        cell = [[thumbCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
       //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];(this works)
    }
    [cell.textLabel setText:@"test"];
    return cell;
}

和拇指细胞子类

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
        [self.textLabel setText:@"thumbCell"];
    }
    return self;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
 static NSString *identifier = @"GroupCell";
thumbCell *cell = [self.testTableView dequeueReusableCellWithIdentifier:identifier];
//UITableViewCell *cell = [self.testTableView dequeueReusableCellWithIdentifier:identifier]; (this works)
if(!cell) {
    cell = [[thumbCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
   //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];(this works)
}
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]];
NSInteger row = indexPath.row;
[cell setCellBackground:sectionRows:row];
[cell.textLabel setText:@"test"];
return cell;
}

在拇指单元格类(自定义单元格类(中

-(void)setCellBackground:(NSInteger)sectionRows:(NSInteger)row
{
UIImage *rowBackground;
UIImage *selectionBackground;
if (row == 0 && row == sectionRows - 1)
{
    rowBackground = [UIImage imageNamed:@"topAndBottomRow.png"];
    selectionBackground = [UIImage imageNamed:@"topAndBottomRowSelected.png"];
}
else if (row == 0)
{
    rowBackground = [UIImage imageNamed:@"topRow.png"];
    selectionBackground = [UIImage imageNamed:@"topRowSelected.png"];
}
else if (row == sectionRows - 1)
{
    rowBackground = [UIImage imageNamed:@"bottomRow.png"];
    selectionBackground = [UIImage imageNamed:@"bottomRowSelected.png"];
}
else
{
    rowBackground = [UIImage imageNamed:@"middleRow.png"];
    selectionBackground = [UIImage imageNamed:@"middleRowSelected.png"];
}
((UIImageView *)self.backgroundView).image = rowBackground;
((UIImageView *)self.selectedBackgroundView).image = selectionBackground;
}

最新更新