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

置き換えてみてください:

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

と:

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

使ってみてください

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