2012-05-02 17 views
0

最初に、この疑問をおかけして申し訳ありません。iPhoneでUITableviewのテキストの配置が機能していない

テーブルビューのセルを作成し、それを中心に配置しようとしました。しかし、これは何もしません。そのまま左に揃えてください。

これは私が使用したコードです。

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


} 

私が間違っているところで誰でも助けてください。

ありがとうございました。

+0

テーブルビューのセルを設定するための異なるコードを提供できますか? – vishiphone

答えて

2

使用indentationLevel

indentationLevelコンテンツ インデントである細胞のインデントレベルを調整します。

@property(nonatomic)NSInteger indentationLevelディスカッションプロパティのデフォルトの の値は0(インデントなし)です。各 インデントの幅は、indentationWidthプロパティによって決まります。

利用状況iOS 2.0以降で利用可能です。

あなたがしたい場合は、独自のラベルを作成し、contentViewにサブビューとして追加することができます UITableViewCell.h

編集で宣言しました。あなたは、すべてのフォーマットとのUITableView細胞のsylesためUITableViewCellStyleSubtitle

+0

私はあなたが私のcode.imを編集する方法を少し詳しく説明してください。Xcode 4.3.2 – suji

+0

for ex:cell.indentationLevel = 10; –

+0

ですが、通常は、loadMore.textLabel.textAlignment = UITextAlignmentCenterを使用して配置を調整できます。このコードはna – suji

0

によって制御されるアライメントtextLabelの配置を変更実装SDSCaseListCustomCellクラスのメソッドのlayoutsubviewsを、あなたが

それでやりたいものは何でもすることはできません

のように

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

} 
. 
. 
. 
@end 
関連する問題