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];

我做错了什么部分请帮忙

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 作为您的类加载以在 tableview 上查看

于 2012-08-10T07:17:31.787 回答