申し訳ありませんが、IOS は初めてで、この問題の解決策がわかりませんでした
これは初心者向けのレストランメニューです
アイテムと価格を含むテーブルビューがあり、1 つのアイテムをクリックすると、ユーザーが数量を入力して完了ボタンをクリックする必要がある別のビューが表示されるので、ユーザーが完了をクリックすると、数量に価格を掛けたいと思います。その特定の価格を取得し、テキストフィールドにユーザーが入力した数量を掛けますか?
これが私のコードです
と呼ばれるメニューヘッダーファイルで NSDictionary を宣言しました
NSDictionary *dict;
私のviewdidloadメソッド
dict=[[NSDictionaryalloc]initWithObjectsAndKeys:
@"TomatoSoup",@"20.00",@"VegManchowSoup",@"12.00",nil];
NSLog(@"%@",dict);
[super viewDidLoad];
このコンテンツを表形式で表示しました
- (NSInteger)tableView:(UITableView *)table numberOfRowsInSection:(NSInteger)section{
return [[dict allKeys]count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
}
NSArray *sortedkeys=[[dict allKeys]sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
NSString *key=[sortedkeys objectAtIndex:indexPath.row];
NSString *value=[dict objectForKey:key];
cell.textLabel.text=value;
cell.detailTextLabel.text=key;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
if(indexPath.row==0){
VegQuantity *vegetarian1 = [[VegQuantity alloc] initWithNibName:@"VegQuantity" bundle:nil];
vegetarian1.m_SelectedIndexPath=indexPath.row;
vegetarian1.pass=dict;
[self presentModalViewController:vegetarian1 animated:YES];
}
if(indexPath.row==1){
VegQuantity *vegetarian1 = [[VegQuantity alloc] initWithNibName:@"VegQuantity" bundle:nil];
vegetarian1.m_SelectedIndexPath=indexPath.row;
[self presentModalViewController:vegetarian1 animated:YES];
}
}
VegQuantity.h テキストフィールドと完了を示すボタンを持つビューがあります。完了ボタンをクリックすると、特定のスープの値を取得し、入力した数量で乗算する必要があります。私の問題は、その特定のキーの価格(値)を取得し、それを数量で乗算する方法です。