MayurCM
MayurCM

Reputation: 701

how to print values for an array in xcode?

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.

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

can anyone help me with this.

Upvotes: 1

Views: 19195

Answers (4)

Sanjeev Rao
Sanjeev Rao

Reputation: 2297

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];

}

Upvotes: 4

Shubhank
Shubhank

Reputation: 21805

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

Upvotes: 0

Yama
Yama

Reputation: 2649

button.title = [myArray objectatindex:index];

Upvotes: 0

X Slash
X Slash

Reputation: 4131

This will do

NSLog(@"%@", myArray);

Upvotes: 13

Related Questions