我正在使用以下代码来显示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/