在Xcode中向表视图单元添加多个图像和字符串

时间:2014-12-07 17:26:32

标签: ios objective-c xcode

问题:

我想要做的是格式化我的表格视图单元格,如下:

[IMG]   CELL_NAME    [IMG]STRING   [IMG]STRING

我已经想出了如何为单元格添加标题图像和名称,但是我无法弄清楚如何使用附加的字符串添加剩余的两个图像。 (见上文)

viewDidLoad中

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    NSString *path = [[NSBundle mainBundle] pathForResource:@"Upgrades" ofType:@"plist"];

    NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];

    upgrades = [dict objectForKey:@"UpgradeStrings"];
    thumbnails = [dict objectForKey:@"UpgradeImages"];

    _regularBubbleLabel.text = [NSString stringWithFormat:@"%li", [RWGameData sharedGameData].regularBubbleCount];
    _premiumBubbleLabel.text = [NSString stringWithFormat:@"%li", [RWGameData sharedGameData].premiumBubbleCount];
}

的cellForRowAtIndexPath

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    // Handles appearance of cells in table.

    static NSString *TableIdentifier = @"TableCell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TableIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:TableIdentifier];
    }

    cell.textLabel.text = [upgrades objectAtIndex:indexPath.row];
    cell.imageView.image = [UIImage imageNamed:[thumbnails objectAtIndex:indexPath.row]];

    return cell;
}

0 个答案:

没有答案