0

私のアプリケーションでは、テーブルビューセルのtextlabelとdetailtextlabelの位置を調整しようとしています。

- (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 =@"name";
    cell.detailTextLabel.text=@" status";

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

  return cell;
}

「しかし、効果がないようです。誰かが私が間違っているところを私に指摘するのを手伝ってくれますか?

4

3 に答える 3

3

textLabelであり、detailTextLabel変更readonlyすることはできません。

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

こちらをご覧ください

于 2012-10-25T13:34:02.713 に答える
2

私が提案するのは、UITableViewCell代わりにカスタムを作成できることです。そのコンテンツをより詳細に制御し、そこにカスタム サブビューを追加することもできます。

そのためのチュートリアルを次に示します。

IBから

コードから

于 2012-10-25T13:34:19.127 に答える
2

layoutSubviews メソッドをオーバーライドする必要があります

customcell クラスを作成し、uitableviewcell で継承する

@このコードを試してください

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
于 2012-10-25T13:38:43.360 に答える