0

私はカロリーカウンターを作成しており、食品のリストを提供する UIAlertView を作成しました。NSMutableDictionary食品とカロリーを含む を作成しました。

@implementation FoodDatabase

-(id)init 
{    
  self = [super init];
  if(self) 
  {
    food= [[NSMutableDictionary alloc] init];
    [food setObject:@"111" forKey:@"Rice"];       
  }
  return self;
}


-(NSString *) foodList: (NSString *) foodItem 
{
    for(NSString *key in [food allKeys]) 
    {        
        if([foodItem isEqual: key]) 
        {
            NSLog(@"%@",foodItem);
            return [food objectForKey:foodItem];
        }
    }
 }


@end

別のクラスではUIAlertView、食品のリストを提供する を作成しました。以下は、Rice アイテムのコード スニペットです。

NSString *buttonTitle = [alertView buttonTitleAtIndex:buttonIndex];
if([buttonTitle isEqualToString:@"Rice"])
{        
    NSString *xyz = [foodData foodList: @"Rice"];
    food_calorie = ([xyz floatValue]);

    UIAlertView *rice_alert=[[UIAlertView alloc] initWithTitle:@"Enter quantity of rice consumed" message:@"100 gms = 111 calories" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];

    [rice_alert addTextFieldWithValue:@"" label:@"Enter quantity in gms"];

    RiceText = [rice_alert textFieldAtIndex:0];
    RiceText.keyboardType = UIKeyboardTypeNumberPad;
    RiceText.clearsOnBeginEditing = YES;
    RiceText.clearButtonMode = UITextFieldViewModeWhileEditing;
    RiceText.keyboardAppearance = UIKeyboardAppearanceAlert;
    rice_alert.tag = RiceAlertView;

    [rice_alert show];
    [rice_alert release];

}

_RiceText_ユーザーが に入力した値と_object_、特定のキー (この場合は米) に対して返されたの値を使用して、総カロリーを計算します。しかし、 の値が に示さ_object_れているように、 の値を返していないようです。どこが間違っていますか??NSLog_(null)__xyz_

4

1 に答える 1