8

When trying to print a name when the ID number is the same as what I entered in...

 2 years ago
source link: https://www.codesd.com/item/when-trying-to-print-a-name-when-the-id-number-is-the-same-as-what-i-entered-in-the-text-field.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

When trying to print a name when the ID number is the same as what I entered in the text field

advertisements

what i would like to know is how would i display the name of a customer (it is an object instance of the object Customer) using the ID number attached to it. this is what i have tried so far and it is not working:

int number = [nunmber intValue];
Customer *customer = [list objectAtIndex:(memberNumber == number)];
NSLog(@"member:%@",customer.name);
NSLog(@"number:%i",number);

all this does is it prints the name of the first person in the table
thanks for any help.
i am programming in xcode 4 for osx


You have to iterate (fast enumeration) over the list:

for (Customer *c in list) {
  if ([c memberNumber]==nunmber) {
    NSLog(@"member %@ with number %@ found",[c name],[c memberNumber]);
  }
}

Provided that nunmber and memberNumber are of same type. Your approach with ...:(memberNumber==number) will either give you the first element (if memberNumber!=number) with index 0 or the second element (if memberNumber==number), since you effectively perform a test and consequently get a boolean with either 0 or 1.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK