title: How to get index in an mutable array?
body: <p>I know <code>indexOfObject</code> could return the index of the element in an array, but I check this method is an <code>NSArray</code> method rather than an <code>NSMutableArray</code> method, and the element in my array is object, does that matter? Because currently my program crashes when the following code gets invoked.</p>
  
  <pre><code>Class *obj = [[Class alloc] init];
  obj.textField1 = outlet1.text;
  obj.textField2 = outlet2.text;
  NSUInteger index = [myMutableArray indexOfObject:obj];
  outlet1.text = [[myMutableArray objectAtIndex:index-1] textField1];
  outlet2.text = [[myMutableArray objectAtIndex:index-1] textField2];
  [obj release];
  </code></pre>
  
  <p>What I am trying to do here is when I call above code, those outlets show the details of the previous object in the array. HELP?</p>
  
  <p>Ok, here is what I really want to do:</p>
  
  <p>I want to create an object by entering stuff in two text fields, then store the object in an array. The array I'm talking about is already declared in the header file and allocated space. The above code is actually a method to show the previous object that's already created. The first three lines are intended to make an object that represents the current one showing in the text fields. Then I want to look it up in my array and get the index of it. The reason I use "index-1" is because I want to see the previous object I created. And by "crash" I mean the program simply exits and goes back to the home screen on my simulator.
  Thanks!</p>
  
  <hr>
  
  <p>All right, I have finally worked out my solution to my problem, I found another way to get the current object, instead of "creating" an "new" object and compare it with ones in the array, I use a flag to record the index of the current object on the screen and decrement it to get the previous object. Anyway, thank you guys.</p>