该应用程序应该像这样工作:用户在文本字段中输入特定状态。在另一个文本字段中,用户输入该州的大写字母。
用户点击“添加”按钮后,键/值对被发送到两个字典中,一个用于将 State 与 Capital 配对,另一个用于将 Capital 与 State 进行比较。
所以这是我的问题:
综上所述,应用程序以编程方式在滚动视图中创建按钮、状态或输入到第一个字段中的任何数据都被表示。
无论哪种情况,该特定按钮都应该在单击时将该按钮的名称切换为配对的 Capital 或 State。对于我的一生,我无法找出如何将其编码到我的应用程序中。
我的头文件:
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
我对编程很陌生,并且正在参加暑期课程,它非常紧凑。我的教授进进出出实验室,但仅提供有关如何成功实现此应用程序的提示。我试图通过网络和我的书来了解如何做到这一点,但到目前为止还没有成功。