简体   繁体   中英

UITableviewCell textLabel not visible in ios7

I am using following code to display cell of 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;

its working fine in ios 6 , its showing textlabel in ios6 , but in ios7 its not showing textLabel.

Except textLabel everything is working fine in ios7.

And one more thing before writing sizetofit, frame of textLabel was (0,0,0,0)

but after adding sizetofit its (0,0,12,15), even though its not showing textLabel.

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

Just replace your code with this one:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM