如何在 xcode 中打印数组的值?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8937573/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 23:02:52  来源:igfitidea点击:

how to print values for an array in xcode?

objective-ciosxcode

提问by MayurCM

I have a text box in my XIB named "txt" and a button named "next". Now on the click of next button I want to print values of myArray.

我的 XIB 中有一个名为“txt”的文本框和一个名为“next”的按钮。现在单击下一步按钮,我想打印 myArray 的值。

NSArray *myArray
 myArray = [NSArray arrayWithObjects:@"1",@"3",@"5",@"45",@"67",nil];

can anyone help me with this.

谁能帮我这个。

回答by X Slash

This will do

这会做

NSLog(@"%@", myArray);

回答by Sanjeev Rao

NSArray *myArray  = [NSArray arrayWithObjects:@"1",@"3",@"5",@"45",@"67",nil];
-(IBAction)nextAction:(id)sender{

NSString *currentObj = txt.text;
int index = -1;

if(currentObj != nil&&[myArray containsObject:currentObj]){
index = [myArray indexOfObject:currentObj];
} 

index++;
if(index<myArray.count)
   txt.text = [myArray objectAtIndex:index];

}

回答by Sarah

button.title = [myArray objectatindex:index];

回答by Shubhank

NSArray *myArray myArray = [NSArray arrayWithObjects:@"1",@"3",@"5",@"45",@"67",nil];

change it to

将其更改为

NSArray *myArray = [NSArray arrayWithObjects:@"1",@"3",@"5",@"45",@"67",nil];

Otherwise you are doomed: D

否则你注定要失败:D