NSMuttableArray...

Discussion in 'iPhone/iPad Programming' started by kurkah, Apr 5, 2011.

  1. macrumors newbie

    Joined:
    Apr 22, 2010
    Location:
    U.K.
    #1
    Hi guys,

    Just working on a project using the iPhone accelerometer, i seem to be struggling with a simple prob..
    I am basically storing the accelerometer values into an array using a button. I am doing this several times (but all stored in SAME array).

    I then have a method that checks every value with its proceeding value
    e.g
    if the first reading was 10 4 6 9
    this method would check 10 with 4, 4 with 6 and 6 with 9.

    So far this is fine, but if the accelerometer data is saved several times..
    e.g. first reading = 10, 4, 6, 9
    second reading = 7, 5, 2, 8

    What i wanted the method to do is compare the values in the first reading then compare the values in the second reading. but the method is comparing every value with its proceeding one since all the values are in the same array.

    How would i overcome this pro.

    cheers in advance::
     
  2. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #2
  3. thread starter macrumors newbie

    Joined:
    Apr 22, 2010
    Location:
    U.K.
    #3
    Yes i am aware of the accelerometer's capability. But i am only working with the X readings for now..

    The acceleration.x readings are casted into integers and saved in a stroreArray, In a button press the values are saved, when the button is pressed again different set of values are saved...

    I have this code in the method i am trying to compare the values from the accelerometer reading.

    Code:
    .
    .
    int value=0;
    for (int i=0;i<storeArray; i++) {		
    {
    if ([[storeArray objectAtIndex:i] intValue] == x && [[storeArray objectAtIndex:i+1] intValue] == y) 
    	{		
    		value++;
    	}
    [array2 replaceObjectAtIndex:position withObject:[NSNumber numberWithFloat:value]];					
    
    }
    
     
  4. macrumors regular

    Joined:
    Jul 17, 2002
    #4
    storeArray is of type NSMutableArray* ? Then why do you loop on the condition "i<storeArray"?
     
  5. Moderator

    balamw

    Staff Member

    Joined:
    Aug 16, 2005
    Location:
    New England
    #5
    Don't assume we can read your mind.

    The details of how you pull the accelerometer data out, cast it and stuff it in storeArrayay be where the problem lies.

    As the last post shows you need to give us more context. How is storeArray declared?

    B
     

Share This Page