【问题标题】:how to set NSArray values to UILabel如何将 NSArray 值设置为 UILabel
【发布时间】:2014-07-18 06:08:37
【问题描述】:

我正在使用 xml 解析并将我的值存储在名为 fetchedobj 的数组中。现在我希望将数组 fetchedobj 中的值显示给 UILabel。

有五个 UILabel 并且单击一个按钮我希望五个值显示在五个 UILabel 上。下次单击时,值将递增,UILabels 应使用下一组五个值进行更新

for ( i=0; i<fetchedobj.count; )
    {
        n1.text=[[fetchedobj objectAtIndex:i]valueForKey:@"tag"];
        n2.text=[[fetchedobj objectAtIndex:i]valueForKey:@"person"];
        n3.text=[[fetchedobj objectAtIndex:i]valueForKey:@"place"];
        n4.text=[[fetchedobj objectAtIndex:i]valueForKey:@"gENDER"];
         n5.text=[[fetchedobj objectAtIndex:i]valueForKey:@"ph"];



        i++;
    }

使用此代码,最后一个人的详细信息会显示在 UILabel 上。请帮忙

【问题讨论】:

    标签: ios objective-c


    【解决方案1】:

    如果我的问题是正确的,你想这样做—— 首先创建一个全局 NSInteger 变量,并在 viewDidLoad() 中将其赋值为 0。 (即 currentIndex = 0)。并使用这个

     -(IBAction)btnClicked:(id)sender 
     {
        currentIndex = currentIndex + 1;  
        if(currentIndex >[fetchedobj count]-1 )
              currentIndex = 0;  
    
        // here set your values  
       n1.text=[[fetchedobj objectAtIndex: currentIndex]valueForKey:@"tag"];
       -----
       -----
     }
    

    【讨论】:

      猜你喜欢
      • 2018-11-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多