0

I have a table, when I select a row I execute this command:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{


     InfoClienteViewController *infoViewController = [[InfoClienteViewController alloc] init];
     [self.navigationController pushViewController:infoViewController animated:YES];

     [infoViewController setIdt:idt[indexPath.row]];


    NSLog(@"You Select -> %zd",idt[indexPath.row]);

}

In my array (idt) I have this values:

  1. [0] -> 2
  2. [1] -> 3
  3. [2] -> 4

So, when I click in the first row on my table (Now the indexPath.row is [0] ), the NSLog was to show the number 2, but return the number 4451524096, why? and how can I solve it?

2 Answers 2

5

Arrays can't hold plain numbers (primitive data types like int, float, NSInteger, ...), they can only hold objects. So, when you log idt[indexPath.row] as a plain number you get gibberish.

Your log should be:

NSLog(@"You Select -> %@", idt[indexPath.row]);

to properly log the object.

Sign up to request clarification or add additional context in comments.

Comments

0

If your array contains int or integer value then you need to access like this below. But make sure that your array contains all the int values.

//For int data types access it like this

NSLog(@"You Select -> %d", idt[indexPath.row].intValue);

//For integer data types access it like this

NSLog(@"You Select -> %ld", idt[indexPath.row].integerValue);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.