0

客観的に新しい。テーブル ビューに 2 つの値を入れようとしています。これはコードの一部です:

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

    static NSString *CellIdentifier = @"Cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    cell.textLabel.font = [UIFont systemFontOfSize:14]; //Change this value to adjust size
    cell.textLabel.numberOfLines = 2;
    NSString *desc= @"Alight Destination =";
    cell.textLabel.text = desc,[alDescArray objectAtIndex:indexPath.row];    
    return cell;
}

この行cell.textLabel.text = desc,[alDescArray objectAtIndex:indexPath.row]; のテーブルAlight Destination =は、値を追加せずに表示するだけです[alDescArray objectAtIndex:indexPath.row];

私はどの部分を間違って行いましたか plsは助けてください

4

3 に答える 3

6

使用する必要があります

cell.textLabel.text=[NSString stringWithFormate:@"%@ %@",desc,[alDescArray objectAtIndex:indexPath.row];

また

NSString *desc=[NSString stringWithFormart: @"Alight Destination = %@",[alDescArray objectAtIndex:indexPath.row] ];
cell.textLabel.text = desc; 

`

于 2012-08-10T06:17:13.260 に答える
1

次の方法を使用します...

cell.textLabel.text = [NSString stringWithFormat:@"%@ %@",desc,[alDescArray objectAtIndex:indexPath.row]];

お役に立てると思います。

于 2012-08-10T06:19:00.080 に答える
1

サブクラス化 UITableViewCell が役立つと思います。以下のコードを見つけてください。

# INTERFACE FILE

#import <UIKit/UIKit.h>

@interface CustomTableViewCell : UITableViewCell {  
    UIImageView *imageView;
    UILabel *titleLabel1;
    UILabel *titleLabel2;
}

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier;
- (void)setValuesForCell:(YourModal*)agent withIndexPath:(NSIndexPath*)indexPath;

@property(nonatomic,retain) UIImageView *imageView;
@property(nonatomic,retain) UILabel *titleLabel1;
@property(nonatomic,retain) UILabel *titleLabel2;

@end

#IMPLEMENTATION FILE

@implementation CustomTableViewCell
@synthesize titleLabel1,titleLabel2,imageView;


- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
    // Your initialisation if any.
    }
    return self;
}

- (void)setValuesForCell:(YourModal*)modal withIndexPath:(NSIndexPath*)indexPath{
    titleLabel1.text=modal.name;
    titleLabel2.text=modal.description;
    imageView.image=modal.image;

        //Other values you want set from modal
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state.
}

- (void)dealloc {
    [super dealloc];
    [titleLabel1 release];
    [titleLabel2 release];
//Other memory releases
}


@end

あなたのxibでは、テーブルビューで表示するためのクラスとしてCustomTableViewCellをロードできます

于 2012-08-10T07:17:31.787 に答える