0

我是应用程序设计和 Objective-C 的新手。我正在编写一个简单的食物应用程序,其中有一些食物存储在一个数组中,其中包含食物、食物名称、烹饪时间和导致图片的文件名的详细信息。

我试图让字幕工作,但它没有出现。我已经阅读了其他各种帖子,并试图实现一些答案,但没有一个奏效。

这是我的代码,如果有任何明显不正确的地方,请告诉我。谢谢你。

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

    static NSString *CellIdentifier = @"FoodCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil){
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    Food *current = [foodArray objectAtIndex:indexPath.row];


    [cell.textLabel setText:[current name]];
    [[cell detailTextLabel] setText:@[current cookTime]];
    cell.imageView.image = [UIImage imageNamed:[current fileName]];

    return cell;
}
4

3 回答 3

2

代替

[[cell detailTextLabel] setText:@[current cookTime]];

[[cell detailTextLabel] setText:[current cookTime]];

请注意,这假设cookTime是一个NSString. 如果它是其他东西,比如代表分钟的整数,你会做这样的事情:

[[cell detailTextLabel] setText:[NSString stringWithFormat:@"%d minutes", [current cookTime]]];

此外,您可能会发现使用这种格式更容易:

cell.detailTextLabel.text = [NSString stringWithFormat:@"%d minutes", [current cookTime]];
于 2013-07-31T19:11:08.117 回答
0

尝试使用

cell.detailTextLabel.text = [current cookTime];
于 2013-08-02T12:32:45.230 回答
0

尝试替换:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

和:

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
于 2013-07-31T20:13:13.843 回答