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 ??
}
paxdiablo is absolutely right, but in case you’re uncertain of the syntax for pass-by-reference, here is what your code should be:
Things to note:
Have a look at how iOS uses error parameters in methods like NSString initWithContentsOfFile:error: for more examples of how this approach is used.