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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:21:11+00:00 2026-05-28T17:21:11+00:00

The pointer passed into the menuItem methode is alloc and for the Pointer Inside

  • 0

The pointer passed into the “menuItem” methode is alloc and for the “Pointer Inside” a value is registered. But for the “Pointer Outside” the value is “null” … why? I passed in the pointer and it should had been modified in the method?

In the header file:

UIButton *bMenu_time;
UILabel *lMenu_time;

Implementation:

- (void) menuItem: (UIView*)vMenu  menuButton:(UIButton*)bMenu menuLabel: (UILabel*)lMenu  menuPosX: (double)posX   menuLenX: (double)lenX  menuTagNum: (int)tagNum menuText: (NSString*)txtMenu{

    bMenu = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [bMenu setFrame:CGRectMake(posX,0,lenX,25)];
    [bMenu setTag: tagNum];
    [bMenu addTarget:pSelf action:@selector(NewNumber:) forControlEvents:UIControlEventTouchUpInside];
    [vMenu addSubview:bMenu];


    lMenu = [[UILabel alloc] initWithFrame:CGRectMake(posX,0,lenX,25)];
    [lMenu setBackgroundColor:[UIColor lightGrayColor]];
    [lMenu setText:[NSString stringWithFormat:  txtMenu]];
    [lMenu setFont:[UIFont systemFontOfSize:14 ]];
    [lMenu setTextAlignment:UITextAlignmentCenter];
    [vMenu addSubview: lMenu];

    NSLog(@"\nPointer Inside: %@\n", lMenu); // <--------- INSIDE WORKS
}



- (void) menuBuild{     
    pSelf = self;
    theString = @"";


    vMenu = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,25)];
    [pSelf.view addSubview:vMenu];
    [vMenu setBackgroundColor:[UIColor grayColor]]; 


    iTime = 2;
    [self menuItem:vMenu menuButton:bMenu_time menuLabel:lMenu_time menuPosX:240+20 menuLenX:60 menuTagNum:102  menuText:[NSString stringWithFormat:  @"Hold: %d", iTime]];

    NSLog(@"\nPointer Outside: %@\n", lMenu_time); // <----- OUTSIDE is NULL ??
}
  • 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-28T17:21:13+00:00Added an answer on May 28, 2026 at 5:21 pm

    paxdiablo is absolutely right, but in case you’re uncertain of the syntax for pass-by-reference, here is what your code should be:

    - (void) menuItem: (UIView*)vMenu  menuButton:(UIButton **)bMenu menuLabel: (UILabel **)lMenu  menuPosX: (double)posX   menuLenX: (double)lenX  menuTagNum: (int)tagNum menuText: (NSString*)txtMenu{
    
        *bMenu = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [*bMenu setFrame:CGRectMake(posX,0,lenX,25)];
        [*bMenu setTag: tagNum];
        [*bMenu addTarget:pSelf action:@selector(NewNumber:) forControlEvents:UIControlEventTouchUpInside];
        [vMenu addSubview:*bMenu];
    
    
        *lMenu = [[UILabel alloc] initWithFrame:CGRectMake(posX,0,lenX,25)];
        [*lMenu setBackgroundColor:[UIColor lightGrayColor]];
        [*lMenu setText:[NSString stringWithFormat:  txtMenu]];
        [*lMenu setFont:[UIFont systemFontOfSize:14 ]];
        [*lMenu setTextAlignment:UITextAlignmentCenter];
        [vMenu addSubview: *lMenu];
    
        NSLog(@"\nPointer Inside: %@\n", *lMenu); // <--------- INSIDE WORKS
    }
    
    
    
    - (void) menuBuild{     
        pSelf = self;
        theString = @"";
    
    
        vMenu = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,25)];
        [pSelf.view addSubview:vMenu];
        [vMenu setBackgroundColor:[UIColor grayColor]]; 
    
    
        iTime = 2;
        [self menuItem:vMenu menuButton:&bMenu_time menuLabel:&lMenu_time menuPosX:240+20 menuLenX:60 menuTagNum:102  menuText:[NSString stringWithFormat:  @"Hold: %d", iTime]];
    
        NSLog(@"\nPointer Outside: %@\n", lMenu_time); // <----- OUTSIDE is NULL ??
    }
    

    Things to note:

    1. objects passed by reference in the method parameters use **
    2. to pass the address of an object to one of these parameters, use &object when calling the method
    3. to refer to an object that is passed by reference, prefix the variable with *

    Have a look at how iOS uses error parameters in methods like NSString initWithContentsOfFile:error: for more examples of how this approach is used.

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

Sidebar

Related Questions

I ran into my first compiler that changes the lvalue passed to ::delete, but
As I know, when a pointer is passed into a function, it becomes merely
I'm trying to assert that a pointer passed into a Parent class' constructor is
I have a function that has an array pointer passed it to modify stuff
I try to call a function which passed as function pointer with no argument,
What is a smart pointer and when should I use one?
What are Null Pointer Exceptions ( java.lang.NullPointerException ) and what causes them? What methods/tools
Studying the K&R book in C I had a few questions regarding complicated pointer
Using pointer arithmetic, it's possible to assign characters from one array to another. My
So I have a pointer to an array of pointers. If I delete it

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.