Ios 通过从选择器视图填充UIlabel上的数据
我正在创建一个应用程序,其中我正在使用“for循环”创建一个视图列表,并且每个视图都包含很少的标签和pickerViews。当我单击并从pickerView中选择任何值时,我的uilabel会更新,但当我单击任何其他pickerView并从中选择不同的值时,它会更新到以前的每个标签。这样,每个UILabel中只显示最后一个选择器值 我知道发生这种情况的原因,因为我创建了UILabel作为属性,并通过“self”进行访问。但是,如果我不以这种方式访问,那么如何更新该标签的值 示例代码:Ios 通过从选择器视图填充UIlabel上的数据,ios,objective-c,iphone,Ios,Objective C,Iphone,我正在创建一个应用程序,其中我正在使用“for循环”创建一个视图列表,并且每个视图都包含很少的标签和pickerViews。当我单击并从pickerView中选择任何值时,我的uilabel会更新,但当我单击任何其他pickerView并从中选择不同的值时,它会更新到以前的每个标签。这样,每个UILabel中只显示最后一个选择器值 我知道发生这种情况的原因,因为我创建了UILabel作为属性,并通过“self”进行访问。但是,如果我不以这种方式访问,那么如何更新该标签的值 示例代码: for (
for (NSMutableDictionary *itemDict in self.returnItemsArray ) {
self.issueLabel = [[TTTAttributedLabel alloc] initWithFrame:CGRectMake(18, shipmentY+3, 270, 20)];
[_issueLabel setNumberOfLines:0];
[_issueLabel setTextColor:LR_darkgray_color];
[_issueLabel setFont:[UIFont systemFontOfSize:15]];
[_issueLabel setTextAlignment:NSTextAlignmentLeft];
[_issueLabel setTag:index];
[_issueLabel setText:@"Size Change"];
[returnOrderInfoView addSubview:_issueLabel];
}
-(void)picker:(LRPickerView *)picker closedWithSelectedIndex:(NSInteger)index{
if (picker.type == SIZE_PICKER){
[self.issueLabel setText:[[_sizeDictionary objectForKey:selectedVar]uppercaseString]];
}
}
如果需要任何其他信息,请告诉我 根据您的描述,您所有的标签都有相同的参考。要解决这个问题,您需要一种维护单独标签引用的方法,如C中的指针 我建议使用一组标签,而不是只使用
self.issueLabel
。需要将属性添加到类中,例如:
@property NSMutableArray *issueLabels;
初始化标签后,将其添加到数组中,如for循环中所示:
[self.issueLabels addObject:issueLabel];
issueLabels数组中的索引应与self.returnItemsArray
中的索引相对应
然后在选取器:closedWithSelectedIndex:
中,可以使用以下方法从数组中检索标签:
TTTAttributedLabel *issueLabel = ((TTTAttributedLabel *)self.issueLabels[index]);
并使用
[issueLabel setText:[[_sizeDictionary objectForKey:selectedVar]uppercaseString]];
你说“当我点击并选择UILabel中的任何值时,会得到更新,但当我点击任何其他pickerview并从中选择不同的值时,它会更新到以前的每个标签。”这完全没有任何意义。我甚至可以称之为”。