2014-07-18 58 views
-5

我使用xml解析並將我的值存儲在數組中,名爲fetchedobj。現在我想要將數組fetchedobj中的值顯示給UILabel。如何設置NSArray值爲UILabel

有五個UILabels,並點擊一個按鈕,我想要五個值顯示在五個UILabels上。在下次點擊值將遞增,並UILabels應與下一組使用此代碼最後一個人的細節顯示在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++; 
    } 

的更新。 PLZ幫助

回答

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

請發表評論的原因嗎? – Yogendra