2012-08-02 119 views
0

我已經自動生成了一些標籤,現在我需要通過在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

回答

0

,這是因爲我使用了單個標籤我做的事....現在工作得很好,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]]; 

}}

0

您需要通過所有的子視圖抓住只有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