2012-05-02 48 views
0

我很抱歉問這個疑問。UITableview文本對齊方式在iPhone中不起作用

我創建了一個表格視圖單元格,並嘗試將它與中心對齊。但是這沒有做任何事情。只需在左邊對齊即可。

這是我使用的代碼。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    if(indexPath.section == 0){ 


    SDSCaseListCustomCell *customCell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
// if (customCell == nil) 
    { 
     NSArray *cells =[[NSBundle mainBundle] loadNibNamed:@"SDSCaseListCustomCell" owner:nil options:nil]; 

     for (UIView *view in cells) 
     { 
      if([view isKindOfClass:[UITableViewCell class]]) 
      { 
       customCell = (SDSCaseListCustomCell*)view; 
      } 
     } 
    } 
    SDSCase *cases = [caseList objectAtIndex:indexPath.row]; 

    customCell.doctor.text = cases.referredDoctor; 
    customCell.hospital.text = cases.hospital; 
    //customCell.time.text = cases.referredDoctor; 
    customCell.caseId.text =cases.caseId; 


    return customCell; 
    } 
    else 
    { 
     UITableViewCell *loadMore = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
     if (loadMore == nil) 
     { 

      loadMore = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier]; 

     } 


     loadMore.textLabel.text = @"loadMore"; 
     loadMore.textLabel.textAlignment = UITextAlignmentCenter; 

      return loadMore; 
    } 


} 

任何人都可以請幫我,我哪裏出錯了。

感謝advace。

+0

我可以提供不同的代碼來設置tableview中的tableview單元嗎? – vishiphone

回答

2

使用indentationLevel

indentationLevel調整其內容 縮進細胞的縮進級別。

@property(nonatomic)NSInteger indentationLevel Discussion該屬性的默認值爲 爲零(無縮進)。每個 縮進級別的寬度由indentationWidth屬性確定。

供貨情況Available in iOS 2.0及更高。宣佈 UITableViewCell.h

編輯:

如果你願意,你可以創建自己的標籤,並添加作爲一個子視圖的內容查看。你不能改變爲textLabel對齊由UITableViewCellStyleSubtitle

+0

即時消息不清楚。請給我多一點解釋如何編輯我的code.im使用Xcode 4.3.2 – suji

+0

爲例如:cell.indentationLevel = 10; –

+0

但通常我們可以通過loadMore.textLabel.textAlignment = UITextAlignmentCenter;此代碼無 – suji

0

您的所有格式和一個UITableView細胞的syles控制的比對,實現SDSCaseListCustomCell類中的方法layoutsubviews,做任何你想在它

like

@implementation SDSCaseListCustomCell 
. 
. 
. 
-(void) layoutSubviews 
{ 
    [super layoutSubviews]; 
    CGRect tFrame = self.textLabel.frame; 
    tFrame.size.width = 235; 
    self.textLabel.frame= tFrame; 
    self.textLabel.textAlignment = UITextAlignmentCenter; 

} 
. 
. 
. 
@end