0

我已经自动生成了一些标签,现在我需要通过使用 xcode 中的标签获取其他标签的值来覆盖标签中的值。

这是我的onclick代码:

- (IBAction)onClick1:(id)sender 
{

    NSString *title = [(UIButton *)sender currentTitle];
    NSLog(@"title ~~~~~~~~~~~ %@",title);
    for(i=0;i<vCount;i++) {
        pStr = [NSString stringWithFormat:@"%c",[pStrName characterAtIndex:i]];
        [pLblMyLable1 setTag:j+1];  
        iTag = [pLblMyLable1 tag];
        NSLog(@"ssssstttttrrrrriinnnngggg on click %@", pStr);
        if([title isEqualToString:pStr]){
            //pStr = [NSString stringWithFormat:@"%c",[pStrName characterAtIndex:i]];
            NSLog(@"came into if");
            pLblMyLable1.text = pStr;
        //pLblMyLable1 = [self.view viewWithTag:iTag];
        //  pStr = [pLblMyLable1.text:iTag];
            /*pLblMyLable1 = [self.view viewWithTag:1];
            pLblMyLable1 = [self.view viewWithTag:2];
            pLblMyLable1 = [self.view viewWithTag:3];
            pLblMyLable1 = [self.view viewWithTag:4];
            pLblMyLable1 = [self.view viewWithTag:5];
            pLblMyLable1 = [self.view viewWithTag:6];*/
}
4

2 回答 2

0

这是我做的事情,因为我使用了一个标签....现在工作正常,有趣的是工作得很好

NSString *title = [(UIButton *)sender currentTitle];
for(i=0;i<vCount;i++) {
    for (NSString* key in Name){
        UILabel *Select = (UILabel*)[self.view viewWithTag:[key intValue]];
        if ([title isEqualToString:Select.text]) { 
        Str = [NSString stringWithFormat:@"%c",[pStrName characterAtIndex:i]];

}}

于 2012-08-08T06:46:33.410 回答
0

您需要枚举所有仅抓取 UILabel 的子视图。这可以这样做:

for(UIView *subview in self.view.subviews){
    if([subview isKindOfClass:[UILabel class]]){
        NSLog(@"%d", [(UILabel*)subview tag]);
    }
}

这应该让你朝着正确的方向前进。

编辑回应评论:你可以试试这个,看看它是否摆脱了错误。

for(UIView *subview in [self.view subviews]){
        if([subview isKindOfClass:[UILabel class]]){
            NSLog(@"%d", [subview tag]);
        }
}
于 2012-08-02T07:20:44.257 回答