アプリは次のように動作するはずです: ユーザーはテキスト フィールドに特定の状態を入力します。別のテキスト フィールドに、ユーザーはその州の首都を入力します。
ユーザーが「追加」ボタンを押すと、キーと値のペアが両方の辞書に送信されます。1 つは State と Capital のペア、もう 1 つは Capital と State の比較用です。
だからここに私の問題があります:
以上のことをすべて説明し、プログラムで scrollView 内にボタンを作成するアプリ、状態、または最初のフィールドに入力されたデータを表します。
その特定のボタンは、クリックすると、そのボタンの名前をペアの首都または州に切り替えることになっています。私の人生では、これをアプリにコーディングする方法を見つけることはできません。
私のヘッダーファイル:
IBOutlet UIScrollView *scrollView; // for scrollable State / Capital view
IBOutlet UITextField *stateField; // text field for entering state
IBOutlet UITextField *capitalField; // text field for entering capital
// stores the website and passwds
NSMutableDictionary *stateCapital;
NSMutableDictionary *capitalState;
// stores the Buttons representing the passwds
NSMutableArray *buttons;
// stores the info buttons for editing existing passwd
NSMutableArray *label;
// location of the file in which capital are stored
NSString *filePath;
私の実装:
状態を追加するには
// make the keyboard disappear
[stateField resignFirstResponder];
[capitalField resignFirstResponder];
NSString *key = stateField.text; // get the text in tagField
NSString *value = capitalField.text; // get the text in queryField
// test if either field is empty
if (value.length == 0 || key.length == 0)
return; // exit from the method
if ([stateCapital valueForKey:key] == nil) // test if the website already exists
[self addNewButtonWithTitle:key]; // if not, add a new button
[stateCapital setValue:value forKey:key]; // add a new entry in tags
stateField.text = nil; // clear tagField of text
capitalField.text = nil; // clear queryField of text
[stateCapital writeToFile:filePath atomically:NO]; //save the data
首都を追加するには (プロセスを逆にするだけです)
// make the keyboard disappear
[stateField resignFirstResponder];
[capitalField resignFirstResponder];
NSString *key = capitalField.text; // get the text in tagField
NSString *value = stateField.text; // get the text in queryField
// test if either field is empty
if (value.length == 0 || key.length == 0)
return; // exit from the method
if ([capitalState valueForKey:key] == nil) // test if the website already exists
[self addNewButtonWithTitle:key]; // if not, add a new button
[capitalState setValue:value forKey:key]; // add a new entry in tags
stateField.text = nil; // clear tagField of text
capitalField.text = nil; // clear queryField of text
[capitalState writeToFile:filePath atomically:NO]; //save the data
私はプログラミングにかなり慣れていないので、サマーコースを受講しています。非常にコンパクトです。私の教授は研究室に出入りしていますが、このアプリケーションを成功させる方法についてのヒントしか提供していません。これを行う方法については、ウェブと私の本で調べようとしていますが、まだ成功していません。