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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T22:08:52+00:00 2026-05-23T22:08:52+00:00

addTarget:self action:@selector :: NSArray works, but pointers fail on the callBack routine? But calling

  • 0

“addTarget:self action:@selector” :: NSArray works, but pointers fail on the callBack routine? But calling a routine from viewDidLoad works for both NSArray and pointers? What is different about “addTarget:self action:@selector” callBack??

here is a code snippet:

thanks for looking…

file.h

NSArray *nsarrA;
NSString **p_nssB;

file.m

- (void)viewDidLoad {
    nsarrA = [[NSArray alloc] initWithObjects:@"0",@"1",@"2",@"3",@"4",@"5",@"6",nil]; 

    p_nssB = (NSString**)malloc(10*sizeof(NSString*));
    for (int i=0; i<10; i++) {
        p_nssB[i]=[NSString stringWithFormat:@"%d", i];
    }

    [self viewMenu];
}


- (void) viewMenu {    
    UIButton *uibtnMenu = [uibtnMenu addTarget:self action:@selector(actionMenu:) forControlEvents:UIControlEventTouchUpInside];
    [uiviewMenu addSubview:uibtnMenu];

    NSLog(@"nsarrA: %@ %@ %@", [nsarrA objectAtIndex:0], [nsarrA objectAtIndex:1], [nsarrA objectAtIndex:2]);//<--works
    NSLog(@"p_nssB: %@ %@ %@", p_nssB[0], p_nssB[1], p_nssB[2]);//<--Works
}


- (void) actionMenu:  (UIButton *) uibtnMenu{
    NSLog(@"nsarrA: %@ %@ %@", [nsarrA objectAtIndex:0], [nsarrA objectAtIndex:1], [nsarrA objectAtIndex:2]);//<--works
    NSLog(@"p_nssB: %@ %@ %@", p_nssB[0], p_nssB[1], p_nssB[2]);//<--fails(drops out of App)
}
  • 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-23T22:08:52+00:00Added an answer on May 23, 2026 at 10:08 pm

    When you allocate with [NSString stringWithFormat:] the instance is autoreleased. It will be released by the next event cycle. You’ll need to retain the instance.

    So either do:

    [[NSString stringWithFormat:@"%d", i] retain];
    

    or:

    [[NSString alloc] initWithFormat:@"%d", i];
    

    Also, when you release the file.m object you’ll need to do:

    for (int i=0; i<10; i++) {
        [p_nssB[i] release];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using addTarget:action:forControlEvents like this: [newsButton addTarget:self action:@selector(switchToNewsDetails) forControlEvents:UIControlEventTouchUpInside]; and I would like
Take a look at this method: [textButton addTarget:self action:@selector(articleModalWillAppear:) forControlEvents:UIControlEventTouchDown]; When the button is
I have a button which i drags using the code: [myButton addTarget:self action:@selector(dragged:withEvent:) forControlEvents:UIControlEventTouchDragInside];
I have 1 button and 2 methods. One method calls this: [button addTarget:self action:@selector(action1)
Come oon! I am almost looking a day at this! I want to set
In my loadView methoad of my view controller I have the following code: //
Hello I've tried for 3 weeks to solve this issue and it stumps me.
Can some explain how to properly subclass a UIViewController and then load it into
I've created a UIPickerView, which displays on button click. The question is how I
I need to display a view modally. The viewcontroller that needs to be displayed

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.