2012-05-02 51 views
0

我已经创建了一个NSarray,现在我想根据它们的索引在标签中显示它的数据。如何从数组中获取数据?

但不想在表格视图单元格中显示它们。
我想用简单的标签来显示它们。

+0

那么问题出在哪里有帮助吗? –

+0

我想知道如何显示数组的数据使用他们的索引在标签....你有 – iosDev

+0

希望你现在得到的解决方案..花一些时间阅读 - https://developer.apple.com/ library/mac /#documentation/Cocoa/Reference/Foundation/Classes/NSArray_Class/NSArray.html –

回答

1
for (int i=0; i<[yourArr count]; i++) { 
    yourLblObject.text=[NSString stringWithFormat:@"%@",[yourArr objectAtIndex:i]]; 
} 
+0

当我这样做是给对象地址像 - .......但我想显示字符串在标签中... – iosDev

+0

你能告诉我你的数组中有什么? – Kuldeep

+0

.......问题解决了现在工作正常.... – iosDev

1

使用此代码,我认为这将是对你

-(void)viewdidload 
    { 
playerScores = [[NSArray arrayWithObjects:@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",nil] retain]; 
CGFloat y = 20; 
for (int i = 0;i<[playerScores count];i++) { 
    myLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, y, 60, 60)]; 
    myLabel.backgroundColor=[UIColor clearColor]; 

    [myLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:35]]; 
    NSString *text = [NSString stringWithFormat:[playerScores objectAtIndex:i]]; 
    [myLabel setText:text]; 

    [yardsScrollView addSubview:myLabel]; 
    [myLabel release]; 
    y = y+125; 
} 


} 
+0

@virendra如果你有答案告诉我们,如果不是那么也这样我们可以尝试解决你的问题。谢谢 – vishiphone

+0

好吧......它给出一些waring格式不是一个字符串文字和没有格式参数.... – iosDev

+0

在这一行-NSString * text = [NSString stringWithFormat:[arrStudents objectAtIndex:i]]; – iosDev