2014-02-27 38 views
2

我使用以下代碼來顯示的UITableView細胞,的UITableViewCell爲textLabel不可見ios7

static NSString *[email protected]"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後。

的tableview在IOS 7 tableview in ios 7 在IOS的tableview 6 tableview in ios 6

+0

試試這個cell.textLabel.contentMode = UIViewContentModeCenter; –

+0

@CharanGiri嘗試過,但沒有工作。 – ViruMax

回答

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 *[email protected]"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; 
} 
+0

感謝但不工作,你認爲你的代碼的哪一點應該解決我的問題? – ViruMax

+0

我已經檢查過它。工作得很好。所有細胞都顯示'嗨'; – Nivesh666

+0

添加一個解釋,說明你在代碼中糾正的問題是否方便。 – manecosta

相關問題