2012-10-25 60 views
0

在我的應用我試圖調整的實現代碼如下cell.I的爲textLabel和detailtextlabel的位置正在做這樣的'設置文本標籤在tableviewcell中的位置?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 

{ 
    static NSString *CellIdentifier = @"Cell"; 

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
     UIImageView* img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cell_with_arrow.png"]]; 
     [cell setBackgroundView:img]; 
     [img release]; 


    } 

    cell.textLabel.frame = CGRectMake(0,0, 150, 40); 
    cell.detailTextLabel.frame = CGRectMake(155, 55, 150, 40); 
    cell.textLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0]; 
    cell.textLabel.textColor = [UIColor blackColor]; 
    cell.textLabel.backgroundColor = [UIColor clearColor]; 
    cell.textLabel.text [email protected]"name"; 
    [email protected]" status"; 

    cell.detailTextLabel.backgroundColor = [UIColor clearColor]; 
    //cell.detailTextLabel.textAlignment = UITextAlignmenteft; 
    //cell.textLabel.textAlignment = UITextAlignmentLeft; 

    return cell; 
} 

`但似乎沒有人effect.can幫我點我在哪裏錯了?

+0

你嘗試添加自定義的UILabel到tableviewcell的內容查看? – Frade

回答

3

textLabeldetailTextLabelreadonly所以你不能改變它們。

@property(nonatomic, readonly, retain) UILabel *textLabel 
@property(nonatomic, readonly, retain) UILabel *detailTextLabel 

here

2

我的建議是,你可以創建自定義UITableViewCell相反,你將擁有更多的控制權的內容,並可以在裏面添加自定義子視圖以及。

這裏有一些教程是:

From IB

From Code

2

你需要重寫layoutSubviews方法

創建customcell類,並且使用的UITableViewCell

@try繼承這個代碼

CustomCell.h

#import <UIKit/UIKit.h> 

@interface CustomCell : UITableViewCell 

@end 

CustomCell.m

#import "CustomCell.h" 

@implementation CustomCell 

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier 
{ 
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; 
    if (self) { 
     // Initialization code 
    } 
    return self; 
} 

-(void)layoutSubviews{ 

    //Set here your frame 

    self.textLabel.frame = CGRectMake(0, , 320, 30); 
} 

- (void)setSelected:(BOOL)selected animated:(BOOL)animated 
{ 
    [super setSelected:selected animated:animated]; 

    // Configure the view for the selected state 
} 

@end