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

  • Home
  • SEARCH
  • 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 6009349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:57:29+00:00 2026-05-23T01:57:29+00:00

I have a UIViewController. At the top of the UIViewController, I have declared NSMutableArray

  • 0

I have a UIViewController. At the top of the UIViewController, I have declared

NSMutableArray *contacts;

In my viewDidLoad method, I call [self getContacts] which basically initializes my contacts array. It begins by initializing the array, and then it adds some objects:

if(contacts == nil)
   contacts = [[NSMutableArray alloc] init];

[contacts removeAllObjects];
[contacts addObjectsFromArray:[some objects]];

So, now my contacts is initialized. In my viewDidLoad method, I even use contacts, and it works great. Later on, in a method, I need to retrieve the elements of contacts, however I am getting an EXC_BAD_ACCESS. Why is this? Why doesn’t my contacts array keep the objects that I initialized it with in the beginning, and how do I fix this?

EDIT:
The error comes when I select a NavigationBarItem which then triggers a method buttonWasPressed. In that method, I simply have the following:

-(void)buttonWasPressed:(id)sender {
    NSLog(@"button was pressed");
    if(contacts == nil)
       NSLog(@"contacts is nil!");

    NSLog(@"contacts = %@",contacts);
}

And I see “button was pressed” printed, but then there is an EXEC_BAD_ACCESS.

  • 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-23T01:57:30+00:00Added an answer on May 23, 2026 at 1:57 am

    That code all looks good, nothing wrong there. I would guess you are over-releasing elsewhere. Turn on Zombies – add NSZombieEnabled to YES in the executable arguments and it will break on the line so you can see what object is being over-released.

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

Sidebar

Related Questions

I have a UIViewController, on top I put an UIImageView, then a UIScrollView. I
I have a UIViewController that manages the display of some data. When the user
I have an application with 5 UIViewController s each inside a corresponding UINavigationController ,
I have a UINavigationController containing an UIViewController initialized with a UIView. The UINavigationController also
Have just started using Visual Studio Professional's built-in unit testing features, which as I
First a little background info: I have UIViewController that contains a UITableView. In the
I have a UIViewController that returns YES in shouldAutorotateToInterfaceOrientation: for UIDeviceOrientationPortrait and NO for
I have a UIViewController with a UISegmentedControl that swaps out one of 3 UITableViewControllers
I have a UIViewController with its own .xib, and I want to use a
So I have a UIViewController (main application controller is a TabBarController). On this there

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.