UITableviewCell textLabel在ios7中不可见

时间:2014-02-27 07:38:01

标签: ios objective-c uitableview ios7

我使用以下代码显示UITableView

的单元格
static NSString *identifier=@"reusableIdentifier";
        UITableViewCell *cell=(UITableViewCell*)[tableView dequeueReusableCellWithIdentifier:identifier];
        cell=[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        NSLog(@"%d",indexPath.row);
        [cell.textLabel setText:@"hi"];
        cell.textLabel.font = [UIFont fontWithName:@"Verdana" size:12.0];
        [cell.textLabel sizeToFit];
        cell.textLabel.transform =  CGAffineTransformMakeRotation(M_PI_2);
        cell.textLabel.backgroundColor = [UIColor clearColor];
        cell.textLabel.textAlignment = NSTextAlignmentCenter;
        [cell.textLabel setTextColor:[UIColor blackColor]];
        cell.backgroundColor=[UIColor clearColor];
        cell.selectionStyle=UITableViewCellSelectionStyleBlue;
        NSLog(@"textlabel frame %@",NSStringFromCGRect(cell.textLabel.frame));
        return cell;

它在ios 6中运行正常,它在ios6中显示textlabel,但在ios7中它没有显示textLabel。

除了textLabel,ios7中一切正常。

在编写sizetofit之前还有一件事,textLabel的框架是(0,0,0,0)

但是在添加sizetofit之后(0,0,12,15),即使它没有显示textLabel。

ios 7中的tableview tableview in ios 7 ios 6中的tableview tableview in ios 6

1 个答案:

答案 0 :(得分:0)

只需用以下代码替换您的代码:

-(void) viewDidLoad
{
    CGAffineTransform rotateTable = CGAffineTransformMakeRotation(-M_PI_2);
    self.tableView.transform = rotateTable;
    self.tableView.frame = CGRectMake(0, 100,self.tableView.frame.size.width, self.tableView.frame.size.height);
}

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

-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier=@"reusableIdentifier";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];

    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
     NSLog(@"%d",indexPath.row);
    [cell.textLabel setText:@"hi"];

    cell.textLabel.font = [UIFont fontWithName:@"Verdana" size:12.0];
    [cell.textLabel sizeToFit];
    cell.textLabel.transform =  CGAffineTransformMakeRotation(M_PI_2);

    cell.textLabel.backgroundColor = [UIColor clearColor];
    cell.textLabel.textAlignment = NSTextAlignmentCenter;

    [cell.textLabel setTextColor:[UIColor blackColor]];
    cell.backgroundColor=[UIColor clearColor];

    cell.selectionStyle=UITableViewCellSelectionStyleBlue;
    NSLog(@"textlabel frame %@",NSStringFromCGRect(cell.textLabel.frame));

    return cell;
}