Ios 将UIPicker数据存储在NSDictionary中

Ios 将UIPicker数据存储在NSDictionary中,ios,xcode,nsdictionary,uipicker,Ios,Xcode,Nsdictionary,Uipicker,我在包含“类别”的主详细视图中有一个UIPicker。我想将该项目的“类别”设置为NSDictionary。NSDictionary包含“标题”“数量”和“类别”的项 如何将UIPicker数据获取到NSDictionary - (IBAction)categoryTextChanged:(UITextField *)sender { [self.category setObject:sender.text forKey:@"category"]; - (void)configureVi

我在包含“类别”的主详细视图中有一个UIPicker。我想将该项目的“类别”设置为NSDictionary。NSDictionary包含“标题”“数量”和“类别”的项

如何将UIPicker数据获取到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];
    }
}

你有问题吗?是的,我如何存储数据@hotlick如果在选择器视图或表视图中每个元素都要存储多个项,则可以使用自定义类或字典(每个元素)来保存它们。然后把它们都放进垃圾堆里。@HotLicks对不起,这很难解释。我有一个包含项目列表的主详细视图。每个项目都有标题、数量和类别。详细视图有2个UItextFields(用于标题和数量)和一个UIPicker(用于类别)。我想把所有3个变量都存储在项目中,所以每次我回到项目中,信息都在那里。所以??您可以为“项”创建自定义对象,也可以使用字典。(请记住,您不应该在视图元素本身中“存储”任何内容,因为它们是非常短暂的。您必须有自己的“并行”数据的表示形式,通常是一个包含自定义对象或NSMutableDictionary的NSMutableArray。如果您有一个包含节的表视图,您可能需要一个节数组,每个节条目都是单独行的另一个数组。