1

in my application at one place I have to get the index value of a particular object. For this I coded in this manner as shown below.

NSString *a=[NSString stringWithFormat:@"%d",[imagesdmobject.proofID intValue]];
NSLog(@"a value is %@",a);

Here a value is 56 Now I have to get the index of 56 from appdelegate.projectTitlesProofIDArray.

int value=[appdelegate.projectTitlesProofIDArray indexOfObjectIdenticalTo:a];

data in appdelegate.projectTitlesProofIDArray is :

41, 34, 35, 64, 45, 1, 67, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 68, 86, 87, 88, 89, 90, 92, 69, 95, 97, 98, 100, 101, 70, 71, 72, 73, 74, 39, 37, 109, 108, 110, 38, 91, 93, 94, 36, 96, 99, 102, 103, 104, 105, 106, 107, 65, 66, 40, 46, 47, 48, 49, 50, 52, 53, 54, 60, 61, 62, 32, 55, 56, 57, 58, 59, 42, 43, 44, 63, 47, 48, 41, 34, 35, 64, 1, 91, 93, 94, 36, 96, 99, 102, 103, 104, 105, 106, 107, 65, 66, 40, 60, 61, 62, 32, 55, 56, 57, 58, 59, 54, 34, 35, 41, 34, 35, 64, 67, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 68, 86, 87, 88, 89, 90, 92, 69, 95, 97, 98, 100, 101, 70, 71, 72, 73, 74, 39, 37, 109, 108, 110, 38, 91, 93, 94, 36, 96, 99, 102, 103, 104, 105, 106, 107, 65, 66, 40, 46, 47, 48, 49, 50, 52, 53, 54, 41, 34, 35, 64, 45, 1, 67, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 68, 86, 87, 88, 89, 90, 92, 69, 95, 97, 98, 100, 101, 70, 71, 72, 73, 74, 39, 37, 109, 108, 110, 38, 91, 93, 94, 36, 96, 99, 102, 103, 104, 105, 106, 107, 65, 66, 40, 46, 47, 48, 49, 50, 52, 53, 54, 60, 61, 62, 32, 55, 56, 57, 58, 59, 42, 43, 44, 47, 34, 35, 39, 37, 109, 108, 110, 38, 46, 47, 48, 49, 50, 52, 53, 54, 42, 43, 44, 41, 34, 35, 64, 45, 1, 67, 75, 76, 77, 78, 79, 80, 81, 83, 85, 68, 86, 87, 88, 89, 90, 92, 69, 95, 97, 98, 100, 70, 71, 73, 74, 39, 37, 109, 108, 110, 38, 91, 94, 36, 96, 99, 102, 103, 104, 105, 106, 107, 65, 66, 40, 46, 47, 48, 49, 50, 52, 54, 60, 61, 62, 32, 55, 56, 57, 58, 59, 42, 43, 63, 41, 34, 35, 64, 45, 1, 67, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 68, 86, 87, 88, 89, 90, 92, 69, 95, 97, 98, 100, 101, 70, 71, 72, 73, 74, 39, 37, 109, 108, 110, 38, 91, 93, 94, 36, 96, 99, 102, 103, 104, 105, 106, 107, 65, 66, 40, 46, 47, 48, 49, 50, 52, 53, 54, 60, 61, 62, 32, 55, 56, 57, 58, 59, 42, 43, 44, 63, 41, 34, 35, 64, 45, 1, 67, 75, 76, 77, 78, 79, 80, 81, 82, 83, 85, 68, 86, 87, 88, 89, 90, 92, 69, 95, 97, 98, 100, 101, 70, 71, 72, 73, 74, 39, 37, 109, 108, 110, 38, 91, 93, 94, 36, 96, 99, 102, 103, 104, 105, 106, 107, 65, 66, 40, 46, 47, 48, 49, 50, 52, 53, 54, 60, 61, 62, 32, 55, 56, 57, 58, 59, 42, 43, 44, 63, 46

56 is there, but I am getting the incorrect value as 2147483647.

Please help me in this issue. I am stuck at this place.

Carl Veazey
  • 18,392
  • 8
  • 66
  • 81
Naresh
  • 19
  • 2

1 Answers1

0

You need to do this:-

Suppose you array contains:-

[array addObject:@"1"];
[array addObject:@"2"];
[array addObject:@"3"];
[array addObject:@"4"];
[array addObject:@"5"];
[array addObject:@"6"];

Now you need to find the index of object 5

if([array containsObject:@"5"])
{
int index=[array indexOfObject:@"5"];
}
Nitish
  • 13,845
  • 28
  • 135
  • 263
Gypsa
  • 11,230
  • 6
  • 44
  • 82
  • hi gypsa thanks a lot. even i wrote in this manner as below int value=[appdelegate.projectTitlesProofIDArray indexOfObject:@"56"]; that time also i am getting the garbade value. – Naresh Sep 05 '12 at 06:34
  • does your ppdelegate.projectTitlesProofIDArray contains sring or some other data type because @"56" means it is nsstring, show how are you adding data in array. – Gypsa Sep 05 '12 at 06:36
  • you need to post the code of how are you adding data in array. – Gypsa Sep 05 '12 at 06:37
  • hi gypsa i wrote the in this manner if([appdelegate.projectTitlesProofIDArray containsObject:a]) { int value=[appdelegate.projectTitlesProofIDArray indexOfObject:a]; NSLog(@"tag value is %d",value); } even i am not getting. my question is 56 is there in my array then why i am not getting please help me. – Naresh Sep 05 '12 at 06:38
  • 1
    You are understanding my point, the code for extracting index is fine, there is something either with the data type difference or when you are adding data in array.Thats why I asked you to post code of how are you adding data in array. – Gypsa Sep 05 '12 at 06:42
  • hi gypsa ok fine i will post. – Naresh Sep 05 '12 at 06:45
  • 1
    hi got the output. the modifications what i did is NSString *proofstr=[NSString stringWithFormat:@"%@",dmobject.proofID]; [appdelegate.projectTitlesProofIDArray addObject:proofstr]; in this manner i am adding the data in array. here dmobject.proofid is nsstring object but the data what i am getting from the server this proof id is int due to that its happen. thanks – Naresh Sep 05 '12 at 06:48