如何在xcode中使用标签显示标签的值?

问题描述:

我已经自动生成了一些标签,现在我需要通过在xcode中使用其标签来获取其他标签的值来覆盖标签中的值。如何在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];*/ 
} 
+0

这里有你所创建的标签.. ??你还在哪里添加了视图? – Zaraki 2012-08-02 07:11:31

,这是因为我使用了单个标签我做的事....现在工作得很好,intrestingly做工不错

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]]; 

}}

您需要通过所有的子视图抓住只有UILabels枚举。这可以这样做:

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]); 
     } 
} 
+0

谢谢你cory,工作正常 – Manoj 2012-08-02 07:24:39

+0

我有任何子视图未申报错误 – Manoj 2012-08-02 07:30:12

+0

我有一个子视图未声明的错误...那是什么....我对不起,我新xcode – Manoj 2012-08-02 07:32:05