Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6343777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:30:41+00:00 2026-05-24T20:30:41+00:00

I know indexOfObject could return the index of the element in an array, but

  • 0

I know indexOfObject could return the index of the element in an array, but I check this method is an NSArray method rather than an NSMutableArray method, and the element in my array is object, does that matter? Because currently my program crashes when the following code gets invoked.

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];

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?

Ok, here is what I really want to do:

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!


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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:30:42+00:00Added an answer on May 24, 2026 at 8:30 pm

    NSMutableArray extends NSArray and inherits all of its methods. So calling objectAtIndex: on an NSMutableArray is fine.

    Without a crash log I can’t tell what the problem is, but my first guess would be that index-1 is -1 when index is 0, or out of bounds when indexOfObject: returns NSNotFound.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Know this might be rather basic, but I been trying to figure out how
I know I could use pagination gems to accomplish a task like this, but
I know this might be a no-brainer, but please read on. I also know
I know this is a stupid question, but I've looked for 45 mins now
I know that this isn't exactly normalised, but bringing all of the localised data
I know the meaning of this error, but I'm really struggling with it, and
I know LINQ has a SequenceEquals method. This method makes sure each item value
I know the benefits of chaining within PHP but lets say we have this
I know that this may be common knowledge, but is there a way to
I know this is a pretty basic question, but I don't know how to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.