ios - UITableviewCell textLabel在iOS7中不可见

标签 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

iOS 6中的tableview

最佳答案

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

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

关于ios - UITableviewCell textLabel在iOS7中不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22062033/

相关文章:

ios - 下载时播放音频而不下载文件两次?

ios - 当预期的声明让我陷入困境(可能很容易解决)但我生疏了

javascript - iOS Cordova 应用程序 - shouldStartLoadWithRequest

objective-c - 防止 UITableView 滚动到包含 textField 的单元格

objective-c - 如何使用桥接文件将我的 swift 代码合并到现有的 Objective C 项目中

ios - tableviewcell 不会横向拉伸(stretch),即方向改变

ios - TableView 复选标记

iOS 12 不支持部分 PWA 的离线功能

ios - 在 iPad1 和 ios5 问题上禁用保存图像弹出窗口

iphone - 使用 jenkins 构建没有源代码控制的本地 iphone 项目