0

I have a UIPicker within a Master-Detail View that contains 'categories'. I would like to set the 'category' to the NSDictionary for that item. The NSDictionary holds items with 'title' 'quantity' and 'category'.

How can I get the UIPicker data to the NSDictionary?

- (IBAction)categoryTextChanged:(UITextField *)sender {
    [self.category setObject:sender.text forKey:@"category"];
- (void)configureView
{
    // Update the user interface for the detail item.
    if (self.item)
        self.itemText.text = [self.item objectForKey:@"item"];
    if (self.quantity)
        self.quantityText.text = [self.quantity objectForKey:@"quantity"];
    if (self.category){
        self.categoryText.text = [self.category objectForKey:@"category"];
        //self.categoryTextLabel.text = [self.category objectForKey:@"category"];
    }

}
- (void)setCategory:(id)newCategory
{
    if (_category != newCategory) {
        _category = newCategory;
        // Update the view.
        [self configureView];
    }
}
phillipppp
  • 13
  • 4
  • Did you have a question?? – Hot Licks Jul 24 '14 at 03:39
  • Yes, how can I store that data? @HotLicks – phillipppp Jul 24 '14 at 04:45
  • If you have multiple items to store per element in a picker view or table view you can either use a custom class or a dictionary (per element) to hold them. Then put each of those in an NSArray. – Hot Licks Jul 24 '14 at 11:31
  • @HotLicks I'm sorry, it's hard to explain. I have a Master-Detail view that has a list of items. Each item has a title, quantity and category. The detail view has 2 UItextFields (for title and quantity) and a UIPicker (for category). I would like to store all 3 of these variables in the item so each time I go back to it, the information is there. – phillipppp Jul 24 '14 at 19:17
  • So?? You can either create a custom object for your "item" or use a dictionary. (Keep in mind that you should not "store" anything in the view elements themselves, as they are quite transitory. You *must* have your own "parallel" representation of the data, generally an NSMutableArray containing either custom objects or NSMutableDictionarys. And if you have, eg, a table view with sections, you probably want an array for the sections, with each section entry being another array for individual rows. – Hot Licks Jul 24 '14 at 19:34
  • @HotLicks Okay, that seems like how I have it set up, but I just can't get the data from the UIPicker to save. The two UITextFields work fine, but not the UIPicker. Here is what I have: https://www.dropbox.com/s/d65nirs6hz29d2m/GroceryList.zip – phillipppp Jul 24 '14 at 20:21
  • I assume you mean UIPickerView? – Hot Licks Jul 24 '14 at 20:44
  • @HotLicks yes, like this: http://i.imgur.com/3AXzOTg.png – phillipppp Jul 24 '14 at 21:39
  • "Cannot get the data to save" -- do you see the data at all? – Hot Licks Jul 24 '14 at 22:01
  • @HotLicks That was a screenshot before I got the picker loaded with data. So, I am about to set the title, the quantity from the UITextField. I have it set right now for the picker to change what is in the UITextField to whatever is picked on the picker. This works fine. Then I send the values from the 3 text fields to the NSMutableDictionary. The Item and the Quantity work fine. Just the Category won't hold. I attached the .zip of the project. It may help. – phillipppp Jul 24 '14 at 23:30
  • "Won't hold" is not a very good description of a problem. You should edit your question and add the code that is setting "Category" or whatever, and the code around it. – Hot Licks Jul 25 '14 at 02:38
  • @HotLicks I uploaded the whole project. dropbox.com/s/d65nirs6hz29d2m/GroceryList.zip – phillipppp Jul 25 '14 at 03:19
  • That's not how you do it. You include the appropriate excerpts of your code in your question. – Hot Licks Jul 25 '14 at 03:21
  • @HotLicks I have no idea what will be useful for you so I posted a bunch of code. – phillipppp Jul 25 '14 at 03:32
  • Why are you using separate dictionaries for each item? You should have a self.viewData dictionary or some such and put all those items in it. – Hot Licks Jul 25 '14 at 11:07
  • @HotLicks because I have taken one course in iOS development and I have no clue what I am doing. I was only looking for some help on a problem with a project I have due. – phillipppp Jul 26 '14 at 01:23

0 Answers0