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 7999835
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:37:00+00:00 2026-06-04T15:37:00+00:00

I have the following code where I am passing the value of buttonString (an

  • 0

I have the following code where I am passing the value of buttonString (an NSString) to another view controller. the app crashes when buttonString = imageName; is set and then called on the other view controller.

in the .h file of the FirstViewController before the @interface:

extern NSString* buttonString;

in the .m file of the FirstViewController before the implementation:

NSString* buttonString = nil;

and here’s the code:

NSString *imageName = [NSString stringWithFormat:@"myImage_%d.png", selectNum + 1 ];
NSLog(@"imageName is %@", imageName);

[buttonImage setImage:[ImgUtil image:imageName]];

buttonString = imageName;

NSLog(@"buttonString %@", buttonString);

the problem arises in the SecondViewController when this is called:

NSLog(@"button Message is %@", buttonString);

if I remove the buttonString = imageName; from the FirstViewController then the app doesn’t crash.

thanks for any help.

  • 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-06-04T15:37:01+00:00Added an answer on June 4, 2026 at 3:37 pm

    This is happening because buttonString is pointing to a released object.

    From your code segment, imageName is an autoreleased NSString. When you say buttonString = imageName; it just points buttonString to the same address as imageName. After this method is over, imageName gets released and so does the memory to which buttonString was pointing too.

    This is why the app crashes when you refer to buttonString in NSLog.

    Ideally, you shouldn’t be sharing data using global variables like this in Objective C. But if you just want to make this work you need to allocate memory to buttonString when it’s used first. Make sure you do release it when it is of no use later.
    NOTE: It still will be a bad way to do things.

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

Sidebar

Related Questions

I have tried to use the following code to passing value back from the
I have following code in my application: // to set tip - photo in
I have the following code passing a dataView variable to a function and I
I have the following code and when I run it, passing 1000 bytes to
I have the following code: for (i=1; i<=len; i++) { var optcheck = col+'|'+document.getElementById('color').options[i].value;
I have the following model in my view that I am passing to it:
In my view I currently have the following code: <%= Html.Hidden(Cart.CartID, Model.Cart.CartID) %> When
I have a question about passing parameters in Tcl regarding to the following code:
I have following code in my Application. Comments in my code will specify My
I have following code in my application. [self.navigationController pushViewController:x animated:YES]; It will push a

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.